filter()

Built-in FunctionPython 2.0+Intermediate

Returns elements from an iterable for which a function returns True

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
evens = list(filter(lambda x: x % 2 == 0, nums))
print(evens)

filter() is a built-in function that returns elements from an iterable for which a function returns true.

Try in Playground

Tags

builtinfunctioncorefunctional-programmingiteration

Related Items