Odd behaviour with list comprehension
steve at holdenweb.com
Mon Mar 31 06:44:57 CEST 2008
Terry Reedy wrote:
> "Steve Holden" <steve at holdenweb.com> wrote in message
> | Well, the fact that the bound variable in the list comprehension does
> | indeed remain outside the construct is simply the result of an
> | over-zealous wish to emulate for loop semantics. The original reasoning,
> | IIRC, as that since a for loop left its bound variable at the last used
> | value, so should a list comprehension.
> | This was quickly recognized as a mistake, but unfortunately not quickly
> | enough. As it was felt that some people might already have relied on
> | that behavior, it was retained in the interests of preserving backwards
> | compatibility.
> But it will not be retained in 3.0, as I understand it.
> So best to not exploit the deprecated behavior.
Correct. The compatibility break provided by 3.0 allows the developers
to drop this historical grunge.
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list