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:
- 📰 Iterators and Iterables in Python: Run Efficient Iterations
- 📰 How to Use Python Lambda Functions
- 🎬 How to Use Python Lambda Functions
- 📰 How to Use Generators and
yield
in Python - 🎬 Python Generators 101
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
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!