Is a list comprehension blazing fast? This is not easy to answer. But my findings indicate it is similar in speed to copying and modifying an existing iterable.
import time
# For benchmark.
source = [0, 1, 2, 3, 4, 5]
print(time.time())
# Version 1: create list comprehension.
for i in range(0, 10000000):
values = [n * 10 for n in source]
if values[5] != 50:
break
print(time.time())
# Version 2: copy array and multiply values in loop.
for i in range(0, 10000000):
values = source[:]
for v in range(0, len(values)):
values[v] = values[v] * 10
if values[5] != 50:
break
print(time.time())
1440121192.57
1440121193.739 1.16900014877 s: list comprehension
1440121194.668 0.92899990081 s: copy list and for-in