Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Filtering III: Generalized Template

In this lesson, you saw the benefit of what we did in the previous lessons where we broke the list comprehensions down and transformed them into traditional for loops. Doing this helped to make it easier to grasp them.

You also saw a generalized pattern for writing for loops with filtering:

values = [expression for value in collection if condition]
values = []
for value in collection:
    if condition:
        values.append(expression)

Become a Member to join the conversation.