Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 213423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:16:37+00:00 2026-05-11T18:16:37+00:00

What is the upper bound of the range() function and how can I extend

  • 0

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):
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:16:37+00:00Added an answer on May 11, 2026 at 6:16 pm

    range(1, 600851475143) wants to generate a very large list in memory, and you’ll get an out of memory error. To save memory, use xrange instead of range. Unfortunately, xrange doesn’t work with large numbers (it’s an implementation restriction) Example (raises OverflowError):

    for i in xrange(1, 600851475143):
      print i
    

    You can have large minimum or maximum values in your interval with range, if their difference is small. Example:

    x = 1 << 200
    print list(xrange(x, x + 3))
    

    Output:

    [1606938044258990275541962092341162602522202993782792835301376L, 1606938044258990275541962092341162602522202993782792835301377L, 1606938044258990275541962092341162602522202993782792835301378L]
    

    A fancy solution to your original for loop problem:

    def bigrange(a, b = None):
      if b is None:
        b = a
        a = 0
      while a < b:
        yield a
        a += 1
    
    for i in bigrange(1, 600851475143):
      print i
    

    A less fancy solution, which works even if you have continue in the loop body:

    i = 1 - 1
    while i < 600851475143 - 1:
      i += 1
      print i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I include the upper bound in range() function? I can't add by
I'm talking about an action game with no upper score limit and no way
I have an upper bound and a lower bound and I want to return
In PHP, you can do... range(1, 3); // Array(1, 2, 3) range(A, C); //
What is the upper limit for an autoincrement primary key in SQL Server? What
I am an upper level Software Engineering student currently in a Data Structures and
So I have a ListView with an upper limit of about 1000 items. I
The default seems to be upper case, but is there really any reason to
I did the following to upper case the first letter in each word but
I've been arguing with my coworkers about Pascal casing (upper camel case) vs. lower

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.