Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

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:

Python
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.