Incorrect scope of list comprehension variables

Rolando Espinoza La Fuente darkrho at gmail.com
Tue Apr 6 19:58:15 EDT 2010


On Sun, Apr 4, 2010 at 5:20 PM, Paul Rubin <no.email at nospam.invalid> wrote:
[...]
>
>    d[r] = list(r for r in [4,5,6])
>

This have a slightly performance difference. I think mainly the
generator's next() call.

In [1]: %timeit list(r for r in range(10000))
100 loops, best of 3: 2.78 ms per loop

In [2]: %timeit [r for r in range(10000)]
100 loops, best of 3: 1.93 ms per loop

~Rolando



More information about the Python-list mailing list