What does the 'comprehension' part of 'list comprehension' mean?Show Answer
The reason this word is used is because the code in a list comprehension
concisely describes what is in the list, without having to write out each
element. This ultimately comes from the mathematical idea of
Why are list comprehensions specific to the map and filter patterns? Why not add special syntax for accumulation or other types of loops?Show Answer
More syntax has a disadvantage of which you are all probably painfully aware right now: it asks students of the language to learn more! So while concise syntax for common operations makes sense, there can't be special syntax for every possible kind of loop. Map and filter loops are given special syntax because they are so incredibly common and useful. Also, to handle some types of accumulation, you can often apply a map/filter and then use a function on the result, like sum for numbers, or .join (which we'll see more later in the class) to build strings.