Generator Expression

genexpr = (expression for item in collection) 

The above generator expression “template” corresponds to the following generator function:

def generator(): 
    for item in collection: 
        yield expression

Bader, Dan. Python Tricks: A Buffet of Awesome Python Features (p. 244).

Last updated