This commit is contained in:
Rohit Tanwar
2018-01-19 15:47:06 +05:30
parent 2b9ef1451d
commit d4cf9cb418
4 changed files with 36 additions and 0 deletions

16
snippets/compact.md Normal file
View File

@ -0,0 +1,16 @@
### compact
Removes falsey values from a list.
Use `filter()` to filter out falsey values (False, None, 0, and "").
```python
def compact(arr):
return list(filter(lambda x: bool(x), arr))
```
``` python
compact([0, 1, False, 2, '', 3, 'a', 's', 34]); // [ 1, 2, 3, 'a', 's', 34 ]
```

View File

@ -25,6 +25,7 @@ def spread(arg):
```
```python

View File

@ -6,6 +6,7 @@ Uses the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Y
```python
from copy import deepcopy
from random import randint