Jan-30-2019, 06:14 PM
Hello everyone.
I just wrote (well, I would say copy and paste for the most part) a few lines of code as follow in order to test efficiency:
Could you help me and tell me where I'm making a mistake?
Thank you for your time.
Cheers,
OttoBit
I just wrote (well, I would say copy and paste for the most part) a few lines of code as follow in order to test efficiency:
import time start = time.time() a = range(100000) b = [] for i in a: b.append(i*2) # a = range(100000) # b = [i*2 for i in a] end = time.time() print(end - start)as you can see, there are 2 'for' loops, one inside the list (inactive as a comment), the other outside. It's the classical example to display "good" VS "bad" coding method. But here's my issue. I ran both loops in Python 3.7, but the the "good" version is giving 0.0 as result. I tested the same code with Spyder 3 (Anaconda) and it seems working fine with resonable results (one is/should be twice the other).
Could you help me and tell me where I'm making a mistake?
Thank you for your time.
Cheers,
OttoBit