Files
Learn-Python-Programming-Th…/ch05/filter.py
T
adii1823 ef37ce0c4e ch05
2021-10-28 17:38:16 +05:30

11 lines
289 B
Python

# filter.py
# This is not a valid Python module - Don't run it.
>>> test = [2, 5, 8, 0, 0, 1, 0]
>>> list(filter(None, test))
[2, 5, 8, 1]
>>> list(filter(lambda x: x, test)) # equivalent to previous one
[2, 5, 8, 1]
>>> list(filter(lambda x: x > 4, test)) # keep only items > 4
[5, 8]