res { res {for in range( )res[xx dict comprehension equivalent res { localized in comprehension expressionsbut not in loop statements notice that although both set and dictionary comprehensions accept and scan iterablesthey have no notion of generating results on demand--both forms build complete objects all at once if you mean to produce keys and values upon requesta generator expression is more appropriateg ((xx xfor in range( )next( ( next( ( extended comprehension syntax for sets and dictionaries like list comprehensions and generator expressionsboth set and dictionary comprehensions support nested associated if clauses to filter items out of the result--the following collect squares of even items ( items having no remainder for division by in range[ for in range( if = [ { for in range( if = { {xx for in range( if = { lists are ordered but sets are not neither are dict keys nested for loops work as wellthough the unordered and no-duplicates nature of both types of objects can make the results bit less straightforward to decipher[ for in [ for in [ ][ { for in [ for in [ ]{ {xy for in [ for in [ ]{ lists keep duplicates but sets do not neither do dict keys like list comprehensionsthe set and dictionary varieties can also iterate over any type of iterable--listsstringsfilesrangesand anything else that supports the iteration protocolcomprehension syntax summary