Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language 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.

Generalized List Comprehension Structure

Give Feedback

In this lesson, you saw the advantages of using list comprehensions as well as the general structure or pattern to follow when creating them. You learned that list comprehensions are powerful if used correctly and can lead to more concise and readable code.

Here is an example of the structure of a list comprehension:

(values) = [(expression) for (value) in (collection)]

And the equivalent for loop:

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

Rob Black on July 12, 2019

Minor point. The terms “values” on the left suggests that each item is a “value” from the right hand side. Of course the left side results from the expression transforming each value on the right, and the narrative does make that clear. But perhaps the text could be revised slightly to reinforce that point:

(resulting values) = [(expression) for (value) in (collection)]


Become a Member to join the conversation.