4 ms·
Although Raymond Hettinger has also called them generator "comprehensions" in the early proposals, the current documentation calls them "generator expressions".
by aaronchall 11y ago
Although Raymond Hettinger has also called them generator "comprehensions" in the early proposals, the current documentation calls them "generator expressions". And good examples.
Here's how you make those set/dict whatever comprehensions in Python 2.6, before the native syntax is used:
s = set(i for i in xrange(10) if not i%2)
- rectangletangle 11y agoSeems like a comprehension is just a particular form of Python expression.
- aaronchall 11y agoHere's the grammar file: https://docs.python.org/2/reference/grammar.html https://docs.python.org/2/reference/grammar.html Look for dictorsetmaker (for {}) testlist_comp (for generator expressions) and listmaker (for [], i.e. list comprehensions).