Python’s filter()
allows you to perform filtering operations on iterables. This kind of operation consists of applying a Boolean function to the items in an iterable and keeping only those values for which the function returns a true result. In general, you can use filter()
to process existing iterables and produce new iterables containing the values that you currently need.
In this video course, you learned how to:
- Work with Python’s
filter()
- Use
filter()
to process iterables and keep the values you need - Combine
filter()
withmap()
andreduce()
to approach different problems - Replace
filter()
with list comprehensions and generator expressions
With this new knowledge, you can now use filter()
in your code to give it a functional style. You can also switch to a more Pythonic style and replace filter()
with list comprehensions or generator expressions.
For further investigation, check out:
Marco Perez on July 9, 2023
Very very cool. This demystified what was heretofore obscure and scary functions (filter, map, reduce) and syntax (lambdas).
Looking forward to using these lots!