The two following codes accomplish the same task
1)
L=list(range(0,100,10))
Ld0=[x^2 for x in L]
Lc=[]
a=0
for i in range(len(Ld0)):
if (Ld0[i]%6 == 0) & (Ld0[i]<= 3200) :
Lc.append(Ld0[i])
a+=1
2)
L=list(range(0,100,10))
Ld0=[x^2 for x in L]
Ld2=[x for x in Ld0 if (x%6 == 0) & (x<= 3200)]
which can be shown by Lc==ld2
.
If I can fin easily the cpu computation time in adding %time
to the first, this is not the case for the second. How to see which way is the fastest ?