Incorrect scope of list comprehension variables
timr at probo.com
Sun Apr 4 06:58:01 CEST 2010
Alain Ketterlin <alain at dpt-info.u-strasbg.fr> wrote:
>I've just spent a few hours debugging code similar to this:
>d = dict()
>for r in [1,2,3]:
> d[r] = [r for r in [4,5,6]]
Yes, this has been fixed in later revisions, but I'm curious to know what
led you to believe that a list comprehension created a new scope. I don't
that was ever promised.
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list