"Paul Rubin" <[email protected]> wrote in message
news:[email protected]...
> "Frank Millman" <[email protected]> writes:
>> dict((a, b) for a, b in zip(x, y))
>> 100000 loops, best of 3: 16.1 usec per loop
>> {a: b for a, b in zip(x, y)}"
>> 100000 loops, best of 3: 6.38 usec per loop
>
> Hmm, I bet the difference is from the (a,b) consing all those tuples.
>
> Can you try just dict(zip(x,y)) ?
C:\>python -m timeit -s "x = range(65, 91); y = (chr(z) for z in x)"
"dict(zip(x, y))"
100000 loops, best of 3: 11.9 usec per loop
C:\>python -m timeit -s "x = range(65, 91); y = (chr(z) for z in x)" "{a: b
for a, b in zip(x, y)}"
100000 loops, best of 3: 7.24 usec per loop
I ran the dict comp again in case the machine load had changed - it is a bit
slower, but not much.
Frank
--
https://mail.python.org/mailman/listinfo/python-list