Why won't this python code work?

  • Context: Python 
  • Thread starter Thread starter dmatador
  • Start date Start date
  • Tags Tags
    Code Python Work
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
dmatador
Messages
120
Reaction score
1
lists = [(2 * i + 1) for i in range(100)]

i = 0
while (i < 100):
if(lists == 3):
lists.remove(lists)
i = i + 1

print lists

It is giving me an error about the index being out of range. I am new to python and I am not understanding this error.

Edit: Fixed it. This is by no means messy. Pretty simple stuff. Stupid error on my part.
 
Last edited:
Physics news on Phys.org
dmatador said:
lists = [(2 * i + 1) for i in range(100)]

i = 0
while (i < 100):
if(lists == 3):
lists.remove(lists)
i = i + 1

print lists

It is giving me an error about the index being out of range. I am new to python and I am not understanding this error.


This looks a bit messy. What are you trying to do?