What is the upper bound of the range() function and how can I extend it, or alternately what’s the best way to do this:
for i in range(1,600851475143):
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.
range(1, 600851475143)wants to generate a very large list in memory, and you’ll get an out of memory error. To save memory, usexrangeinstead ofrange. Unfortunately,xrangedoesn’t work with large numbers (it’s an implementation restriction) Example (raises OverflowError):You can have large minimum or maximum values in your interval with
range, if their difference is small. Example:Output:
A fancy solution to your original for loop problem:
A less fancy solution, which works even if you have
continuein the loop body: