[Python-Dev] accumulator display syntax
Skip Montanaro
skip at pobox.com
Sat Oct 25 10:15:36 EDT 2003
Tim> [Skip Montanaro]
>> How much more expensive
Tim> Stop right there.
Okay, but I couldn't resist. ;-)
>> for f in math.sin, math.cos, math.tan:
>> squares = (f(x)**2 for x in inputs)
>> plot(squares)
Tim> Despite the similar appearance, that does something very different,
...
>> which would work without reiterability, right?
Tim> Yup.
I shouldn't have mentioned performance. The above was really the point I
was getting at. The mention of performance was simply because I couldn't
understand why reiterability would be necessary in your example. I see you
were just pointing out that someone not understanding the underlying nature
of the generator would assume your example would work *and* save cycles
because the definition of the generator expression was hoisted out of the
loop.
Skip
More information about the Python-Dev
mailing list