4 ms·
Since Python 3, both generators and lists create a new stack frame. [1] (2nd to last paragraph) [1] http://python-history.blogspot.com/2010/06/from-list-compre
by fovc 10y ago
Since Python 3, both generators and lists create a new stack frame. [1] (2nd to last paragraph)
[1] http://python-history.blogspot.com/2010/06/from-list-comprehensions-to-generator.html http://python-history.blogspot.com/2010/06/from-list-compreh...
- warbiscuit 10y agoI'm not meaning when the comprehension is invoked, but during each iteration of the loop within the comprehension. When doing something like `map(lambda x: 2+x, range(100))`, there will be 101 frames created: the outer frame, and 100 for each invocation of the lambda. Whereas `[2+x for x in range(100)]` will only create 2: one for the outer frame, and one for the comprehension.