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):
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Python 2.x:
rangecreates a list, so if you dorange(1, 10000000)it creates a list in memory with9999999elements.xrangeis a sequence object that evaluates lazily.In Python 3:
rangedoes the equivalent of Python 2’sxrange. To get the list, you have to explicitly uselist(range(...)).xrangeno longer exists.