Issue
Apparently xrange is faster but I have no idea why it's faster (and no proof besides the anecdotal so far that it is faster) or what besides that is different about
for i in range(0, 20):
for i in xrange(0, 20):
Solution
In Python 2.x:
range
creates a list, so if you dorange(1, 10000000)
it creates a list in memory with9999999
elements.xrange
is a sequence object that evaluates lazily.
In Python 3:
range
does the equivalent of Python 2'sxrange
. To get the list, you have to explicitly uselist(range(...))
.xrange
no longer exists.
Answered By - Charles
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.