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
So in Java, whenever an indexed range is given, the upper bound is almost
How can I set a lower and upper bound value for a variable in
I am trying to build a range with an upper bound bigger than limit
How can i know upper bound of requests per second my webapp can handle
Is there a upper bound to how many subscriptions one user can have in
I frequently use the following pattern to set an upper bound to the running
I am trying to establish upper / lower bound in my stored procedure below
Is it possible to specify both upper and lower bound constraints on type parameters
I am trying to change the value of upper bound in For loop ,but

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.