Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python reliability?
#1
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:
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
Reply


Messages In This Thread
Python reliability? - by OttoBit - Jan-30-2019, 06:14 PM
RE: Python reliability? - by snippsat - Jan-30-2019, 07:09 PM
RE: Python reliability? - by OttoBit - Jan-30-2019, 09:38 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020