needed in factthis is essentially the same as the prior tradeoff between lambda and def--expression conciseness versus statement powerdef timesfour( )for in syield timesfour('spam'list( ['ssss''pppp''aaaa''mmmm'generator function iterate automatically to clientsthe two are more similar than different both expressions and functions support both automatic and manual iteration--the prior list call iterates automaticallyand the following iterate manuallyg ( for in 'spam' iter(gnext( 'ssssnext( 'ppppg timesfour('spam' iter(gnext( 'ssssnext( 'ppppiterate manually (expressioniterate manually (functionin either casepython automatically creates generator objectwhich has both the methods required by the iteration protocoland state retention for variables in the generator' code and its current code location notice how we make new generators here to iterate again--as explained in the next sectiongenerators are one-shot iterators firstthoughhere' the true statement-based equivalent of expression at the end of the prior sectiona function that yields values--though the difference is irrelevant if the code using it produces all results with tool like joinline 'aa bbb 'join( upper(for in line split(if len( 'aabbbexpression def gensub(line)for in line split()if len( yield upper(function 'join(gensub(line)'aabbbbut why generategenerator functions and expressions