Skip to content

Instantly share code, notes, and snippets.

@minitech
Created February 21, 2017 23:54
Show Gist options
  • Save minitech/e6143997323d1189f6265b1c30fbc219 to your computer and use it in GitHub Desktop.
Save minitech/e6143997323d1189f6265b1c30fbc219 to your computer and use it in GitHub Desktop.
$ python --version
Python 3.6.0

$ python -m timeit -s 'import random; l = list(range(18))' 'random.choice(l)'
1000000 loops, best of 3: 0.591 usec per loop

$ python -m timeit -s 'd = {str(n): list(range(15)) for n in range(18)}' 'd["12"]'                     
10000000 loops, best of 3: 0.0224 usec per loop

Context: a Stack Overflow question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment