('aaa\ ''ccc\ 'notice how the join call in the preceding doesn' require extra parentheses around the generator syntacticallyparentheses are not required around generator expression that is the sole item already enclosed in parentheses used for other purposes--like those of function call parentheses are required in all other caseshowevereven if they seem extraas in the second call to sorted that followssum( * for in range( ) sorted( * for in range( )[ sorted(( * for in range( ))reverse=true[ parens optional parens optional parens required like the often-optional parentheses in tuplesthere is no widely accepted rule on thisthough generator expression does not have as clear role as fixed collection of other objects as tuplemaking extra parentheses seem perhaps more spurious here why generator expressionsjust like generator functionsgenerator expressions are memory-space optimization --they do not require the entire result list to be constructed all at onceas the squarebracketed list comprehension does also like generator functionsthey divide the work of results production into smaller time slices--they yield results in piecemeal fashioninstead of making the caller wait for the full set to be created in single call on the other handgenerator expressions may also run slightly slower than list comprehensions in practiceso they are probably best used only for very large result setsor applications that cannot wait for full results generation more authoritative statement about performancethoughwill have to await the timing scripts we'll code in the next though more subjectivegenerator expressions offer coding advantages too--as the next sections show generator expressions versus map one way to see the coding benefits of generator expressions is to compare them to other functional toolsas we did for list comprehensions for examplegenerator expressions often are equivalent to map callsbecause both generate result items on request like list comprehensionsthoughgenerator expressions may be simpler to code when the operation applied is not function call in xmap makes temporary lists and generator expressions do notbut the same coding comparisons applylist(map(abs(- - ))[ list(abs(xfor in (- - )[ map function on tuple generator expression generator functions and expressions