difference
This commit is contained in:
18
README.md
18
README.md
@ -39,6 +39,7 @@ Use `filter()` to filter out falsey values (False, None, 0, and "").
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
|
|
||||||
def compact(arr):
|
def compact(arr):
|
||||||
return list(filter(lambda x: bool(x), arr))
|
return list(filter(lambda x: bool(x), arr))
|
||||||
|
|
||||||
@ -116,12 +117,29 @@ def spread(arg):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
deep_flatten([1, [2], [[3], 4], 5]) # [1,2,3,4,5]
|
deep_flatten([1, [2], [[3], 4], 5]) # [1,2,3,4,5]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### difference
|
||||||
|
|
||||||
|
Returns the difference between two arrays.
|
||||||
|
|
||||||
|
Create a `set` from `b`, then use list comprehension to only keep values not contained in `b`
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
def difference(a, b):
|
||||||
|
b = set(b)
|
||||||
|
return [item for item in a if item not in b]
|
||||||
|
|
||||||
|
```
|
||||||
|
``` python
|
||||||
|
difference([1, 2, 3], [1, 2, 4]) # [3]
|
||||||
|
```
|
||||||
### gcd
|
### gcd
|
||||||
|
|
||||||
Calculates the greatest common divisor between two or more numbers/lists.
|
Calculates the greatest common divisor between two or more numbers/lists.
|
||||||
|
|||||||
@ -6,6 +6,7 @@ Use `filter()` to filter out falsey values (False, None, 0, and "").
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
|
|
||||||
def compact(arr):
|
def compact(arr):
|
||||||
return list(filter(lambda x: bool(x), arr))
|
return list(filter(lambda x: bool(x), arr))
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@ def spread(arg):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|||||||
16
snippets/difference.md
Normal file
16
snippets/difference.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
### difference
|
||||||
|
|
||||||
|
Returns the difference between two arrays.
|
||||||
|
|
||||||
|
Create a `set` from `b`, then use list comprehension to only keep values not contained in `b`
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
def difference(a, b):
|
||||||
|
b = set(b)
|
||||||
|
return [item for item in a if item not in b]
|
||||||
|
|
||||||
|
```
|
||||||
|
``` python
|
||||||
|
difference([1, 2, 3], [1, 2, 4]) # [3]
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user