arbitrarily mixed and deepthough some may be more valid than otherslist(map(absmap(absmap(abs(- ))))nesting gone bad[ list(abs(xfor in (abs(xfor in (abs(xfor in (- )))[ these last examples illustrate how general generators can bebut are also coded in an intentionally complex form to underscore that generator expressions have the same potential for abuse as the list comprehensions discussed earlier--as usualyou should keep them simple unless they must be complexa theme we'll revisit later in this when used wellthoughgenerator expressions combine the expressiveness of list comprehensions with the space and time benefits of other iterables herefor examplenonnested approaches provide simpler solutions but still leverage generatorsstrengths --per python mottoflat is generally better than nestedunnested equivalents list(abs( for in (- - )[ list(math sqrt( * for in range( )[ list(abs(xfor in (- )[ flat is often better generator expressions versus filter generator expressions also support all the usual list comprehension syntax--including if clauseswhich work like the filter call we met earlier because filter is an iterable in that generates its results on requesta generator expression with an if clause is operationally equivalent (in xfilter produces temporary list that the generator does notbut the code comparisons again applyagainthe join in the following suffices to force all forms to produce their resultsline 'aa bbb 'join( for in line split(if len( 'aabbb'join(filter(lambda xlen( line split())'aabbbgenerator with 'ifsimilar to filter the generator seems marginally simpler than the filter here as for list comprehensionsthoughadding processing steps to filter results requires map toowhich makes filter noticeably more complex than generator expression'join( upper(for in line split(if len( 'aabbb'join(map(str upperfilter(lambda xlen( line split()))'aabbbin effectgenerator expressions do for iterables like map and filter what list comprehensions do for the list-builder flavors of these calls--they provide more general generator functions and expressions