Skip to content
Commit 2071da8d authored by Jon Dufresne's avatar Jon Dufresne
Browse files

Use dict comprehension instead of a dict() constructor

The dictionary comprehension syntax is available on all supported Python
versions. Dictionary comprehension is modern Python syntax and is always
faster than the dict() constructor, e.g.:

  $ python3 -m timeit 'dict((a, a) for a in range(20))'
  100000 loops, best of 3: 2.16 usec per loop
  $ python3 -m timeit '{a: a for a in range(20)}'
  1000000 loops, best of 3: 0.953 usec per loop
parent 88a23e8a
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment