Dict comprehensions - improvement to docs?
Lele Gaifax
lele at metapensiero.it
Tue Mar 17 10:06:08 EDT 2015
"Frank Millman" <frank at chagford.com> writes:
> It seems that a dict comp is noticeably faster.
>
> Does this sound right, or are there other factors I should be taking into
> account?
The dict comp does not execute any function call. Consider the following:
$ python3 -m timeit "d=dict()"
10000000 loops, best of 3: 0.113 usec per loop
$ python3 -m timeit "d={}"
10000000 loops, best of 3: 0.0601 usec per loop
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it | -- Fortunato Depero, 1929.
More information about the Python-list
mailing list