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

  • Home
  • SEARCH
  • 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 9315971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:29:57+00:00 2026-06-19T02:29:57+00:00

So I have been running into a really weird error. I have a module

  • 0

So I have been running into a really weird error. I have a module ten.py containing

import math

def go():
    list_ = list(range(3, 100000, 2))
    max_ = int(math.sqrt(len(list_)))
    print(len(list_))
    print(max_)
    for i in range(1,max_):
        print(i)
        current = list_[i]
        for j in list_[i+1:]:
            if j % i == 0:
                list_.remove(j)
go()

The output is this:

49999
223
1
2
Traceback (most recent call last):
  File "D:\Documents\KomodoProjects\Project Euler\ten.py", line 14, in <module>
    go()
  File "D:\Documents\KomodoProjects\Project Euler\ten.py", line 10, in go
    current = list_[i]
IndexError: list index out of range

As you can see the size of list is 49999 and the for loop only goes to 223. Despite all this it already gives an index out of range exception at index=2!

Is the list_ inside the for loop somehow not referencing to the list_ inside go()? I have no clue as to why this problem occurs.

Fixed by changing

for i in range(1,max_):

to
for i in list_:

  • 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-06-19T02:29:58+00:00Added an answer on June 19, 2026 at 2:29 am

    Here is your problem:

    You have a for loop that is deleting numbers from list_. It is deleting so many numbers that list_ is length 2, and then list_[2] fails and raises an exception.

    The reason it is deleting so many numbers is that you are computing x % 1 == 0 which is true for any value of x. Since you start at position 2 in the list, you are deleting everything after that position.

    I’m not certain exactly what you are doing but this is going to be a slow way to do it, whatever it is. This looks sort of like screening for prime numbers… you might want to do a Google search for “Python find prime numbers” or something.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been running into this error for the last 3 or 4 weeks
So I have been running into all kinds of interesting problems in VisualStudio 2008
I have been trying to learn Erlang and have been running into some problems
I have been using this code, but have been running into some memory issues:
I'm exploring package building on Windows 7 but have been running into trouble after
I have been attempting to learn Grails, however I am running into the following
I have been looking into Ember.js , and it looks really great, but one
So, this was quite an interesting problem I have been running into. I am
I have ran into a really annoying issue which gives me this error: The
I have been running into this problem sometimes when programming. Imagine I have a

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.