5
I finally understood why my loops kept breaking after a chat at the Denver library
I was trying to make a simple list of numbers in Python, but my code kept stopping early. A guy next to me at the library coding group pointed out I was changing the list while my loop was running through it. He said, 'You're removing items as you go, so the list gets shorter and the loop gets confused.' I had to make a copy of the list to loop over instead. Has anyone else run into this problem with for loops?
2 comments
Log in to join the discussion
Log In2 Comments
evan_carr21d ago
Yeah, that exact thing tripped me up for days once.
2
leo_thomas221d ago
Days? That's actually insane.
3