[Python-ideas] "While" suggestion
tjreedy at udel.edu
Wed Jul 30 04:55:51 CEST 2008
Steven Bethard wrote:
> On Tue, Jul 29, 2008 at 3:19 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> Roman Susi wrote:
>>> Python already has dict/list literals + list comprehensions.
>> Better to think that Python has generator expressions which can be used in
>> list, set, and dict comprehensions (the latter two in 3.0 and maybe 2.6).
> You probably don't want to think about it that way - a list/set/dict
> comprehension does not actually create a generator.
Yes I do. For normal purposes, in 3.0, [genexp] == list(genexp), and so
on. That it do something else internally for efficiency is
implementation detail, not semantics.
> Instead, it basically just inlines the equivalent for loop.
In 3.0, not quite. The manual says "Note that the comprehension is
executed in a separate scope, so names assigned to in the target list
don’t “leak” in the enclosing scope." The difference between this and
the conceptual equivalence above is one function call versus many. Were
you using 2.6?
More information about the Python-ideas