Python Forum
.remove() method in for-loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.remove() method in for-loop
#4
Or you could do a list comprehension:

sw = [item for item in sw if item != 'bo']
For large lists, that would probably be more efficient. Filter might be even more efficient.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
.remove() method in for-loop - by nzcan - Oct-08-2018, 07:39 PM
RE: .remove() method in for-loop - by ichabod801 - Oct-08-2018, 08:25 PM
RE: .remove() method in for-loop - by TimeMen - Oct-08-2018, 08:30 PM
RE: .remove() method in for-loop - by ichabod801 - Oct-08-2018, 08:34 PM
RE: .remove() method in for-loop - by snippsat - Oct-08-2018, 10:23 PM
RE: .remove() method in for-loop - by ichabod801 - Oct-09-2018, 01:04 AM
RE: .remove() method in for-loop - by snippsat - Oct-09-2018, 02:07 PM
RE: .remove() method in for-loop - by gruntfutuk - Oct-13-2018, 07:05 PM

Forum Jump:

User Panel Messages

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