11 lines
289 B
Python
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]
|