filter()
say it: “FIL-ter” /ˈfɪltər/
Keeps only the items that pass a test.
What does filter() do?
filter() keeps only the items that pass a test.
ages = [12, 19, 35, 16]
adults = list(filter(lambda age: age >= 18, ages))
print(adults) # [19, 35]
Level: Journeyman · More Python terms at this level
Updated