Monday, December 2, 2019

itertools product 3x faster than list comprehension

>>> timeit.timeit('list(itertools.product([1,2,3,4],["a","b","c","d"]))',number=100)
0.00015309499997329112
>>> timeit.timeit('[(x,y) for i,x in enumerate([1,2,3,4]) for j,y in enumerate(["a","b","c","d"])]',number=100)
0.00034536499998694126
>>>

No comments:

Post a Comment