Last active
September 13, 2018 14:06
-
-
Save srusskih/77037c6b6fd8cd9cf55ce52c19f8ae76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
a = [(i, i - 1) for i in range(10000)] | |
def t1(): | |
d = collections.defaultdict(lambda: [].append) | |
for i in a: | |
d[i[0]](i) | |
def t2(): | |
d = collections.defaultdict(list) | |
for i in a: | |
d[i[0]].append(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
timeit.timeit(''' | |
import collections | |
a = [(i, i - 1) for i in range(10000)] | |
def t1(): | |
d = collections.defaultdict(lambda: [].append) | |
for i in a: | |
d[i[0]](i) | |
t1()''', number=1000) | |
timeit.timeit(''' | |
import collections | |
a = [(i, i - 1) for i in range(10000)] | |
def t2(): | |
d = collections.defaultdict(list) | |
for i in a: | |
d[i[0]].append(i) | |
t2()''', number=1000) |
Author
srusskih
commented
Sep 13, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment