What is the fastest and pythonic way to generate a list [(0,0), (0,1), (0,2)…(0,100)]? [closed]

If you want a faster solution you can use itertools.repeat:

from itertools import repeat:

list(zip(repeat(0), range(101)))

benchmark:

%timeit [(0, x) for x in range(101)]
# 3.64 µs ± 19.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

%timeit list(zip(repeat(0), range(101)))
# 2.81 µs ± 35.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Another Pythonic solution:

list((0, x) for x in range(101))

Browse More Popular Posts

Leave a Comment