On Tue, Mar 17, 2015 at 12:44 AM, Frank Millman <fr...@chagford.com> wrote: > Thanks for the explanation. I'll try not to make that mistake again. > > However, to go back to the original example, we want to compare a dict > comprehension with a dict() constructor using a generator expression. > > Let's see if I have got this one right - > > C:\>python -m timeit -s "x=range(65, 91); y=[chr(z) for z in x]" "dict((a, > b) for a, b in zip(x, y))" > 10000 loops, best of 3: 49.6 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)}" > 10000 loops, best of 3: 25.8 usec per loop
Why did you revert back to the no-op generator expression in the first case instead of the more efficient dict(zip(x, y))? -- https://mail.python.org/mailman/listinfo/python-list