Operators, Expressions, and Data Manipulation
List, Set, and Dictionary Comprehension
List Comprehension
Set Comprehension
Dictionary Comprehension
Generator Expression
List Comprehension vs. Generator Expression
Wiith a list comprehension, Python actually creates a list that contains the resulting data. With a generator expression, Python creates a generator that merely knows how to produce data on demand. In certain application, this can greately improve performance and memroy use. Here is an example:
Last updated
Was this helpful?