Python Forum
Error in loops, new to Python
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in loops, new to Python
#14
I think the easy solution is to just iterate over a copy of the list, ie: for x in some_list[:]:, but then if the list is large (or is a generator and doesn't exist fully yet), that could just eat memory. Maybe for x in (item for item in some_list):? That way you can modify the original list, without changing how you iterate. Could make for confusing results sometimes, though.
Reply


Messages In This Thread
Error in loops, new to Python - by jhall710 - Apr-17-2017, 10:42 PM
RE: Error in loops, new to Python - by nilamo - Apr-18-2017, 02:18 AM
RE: Error in loops, new to Python - by jhall710 - Apr-18-2017, 02:27 AM
RE: Error in loops, new to Python - by nilamo - Apr-18-2017, 02:28 AM
RE: Error in loops, new to Python - by jhall710 - Apr-18-2017, 02:35 AM
RE: Error in loops, new to Python - by nilamo - Apr-18-2017, 03:29 AM
RE: Error in loops, new to Python - by sparkz_alot - Apr-18-2017, 12:50 PM
RE: Error in loops, new to Python - by smbx33 - Apr-23-2017, 10:19 AM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 03:43 AM
RE: Error in loops, new to Python - by smbx33 - Apr-24-2017, 04:32 AM
RE: Error in loops, new to Python - by volcano63 - Apr-24-2017, 06:41 PM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 04:05 PM
RE: Error in loops, new to Python - by wavic - Apr-24-2017, 06:47 PM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 06:47 PM
RE: Error in loops, new to Python - by wavic - Apr-24-2017, 06:53 PM
RE: Error in loops, new to Python - by volcano63 - Apr-24-2017, 07:02 PM
RE: Error in loops, new to Python - by zivoni - Apr-24-2017, 07:50 PM
RE: Error in loops, new to Python - by volcano63 - Apr-24-2017, 08:16 PM
RE: Error in loops, new to Python - by smbx33 - Apr-24-2017, 08:49 PM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 09:44 PM
RE: Error in loops, new to Python - by smbx33 - Apr-25-2017, 05:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New to python! Loops Seeley307 3 70,297 May-15-2020, 02:27 PM
Last Post: ibreeden
  Python for loops giving error Petrus 12 5,685 Jan-09-2019, 08:02 AM
Last Post: Petrus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020