comprehension was extended to other roles--setsdictionariesand even the value generator expressions we'll explore in this it' not just for lists anymore we first met list comprehensions in ' previewand studied them further in in conjunction with looping statements because they're also related to functional programming tools like the map and filter callsthoughwe'll resurrect the topic here for one last look technicallythis feature is not tied to functions--as we'll seelist comprehensions can be more general tool than map and filter--but it is sometimes best understood by analogy to function-based alternatives list comprehensions versus map let' work through an example that demonstrates the basics as we saw in python' built-in ord function returns the integer code point of single character (the chr built-in is the converse--it returns the character for an integer code pointthese happen to be ascii codes if your characters fall into the ascii character set' bit code point rangeord(' ' nowsuppose we wish to collect the ascii codes of all characters in an entire string perhaps the most straightforward approach is to use simple for loop and append the results to listres [for in 'spam'res append(ord( )manual results collection res [ now that we know about mapthoughwe can achieve similar results with single function call without having to manage list construction in the coderes list(map(ord'spam')res [ apply function to sequence (or otherhoweverwe can get the same results from list comprehension expression--while map maps function over an iterablelist comprehensions map an expression over sequence or other iterableres [ord(xfor in 'spam'res [ apply expression to sequence (or otherlist comprehensions collect the results of applying an arbitrary expression to an iterable of values and return them in new list syntacticallylist comprehensions are enclosed in square brackets--to remind you that they construct lists in their simple formwithin comprehensions and generations