using for loop in single lines:
%%time
y = [x*2 if x%2 != 0 else x+2 for x in range(10000000)]
CPU times: user 1.27 s, sys: 150 ms, total: 1.42 s
Wall time: 1.42 s
using for loop in multiple lines:
%%time
y =[]
for x in range(10000000):
if x%2 != 0:
y.append(x*2)
else:
y.append(x+2)
CPU times: user 2.45 s, sys: 198 ms, total: 2.65 s
Wall time: 2.65 s
Why second for loop is taking more time? Both are doing the same thing.