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

Unlock This Lesson

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

Unlock This Lesson

Filtering III: Generalized Template

Give Feedback

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)

Comments & Discussion

Become a Member to join the conversation.