compact
This commit is contained in:
16
snippets/compact.md
Normal file
16
snippets/compact.md
Normal 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 ]
|
||||
```
|
||||
@ -25,6 +25,7 @@ def spread(arg):
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user