You could always iterate over a copy of the list, leaving you free to modify the original:
for item in list(somelist):
...
somelist.remove(item)
More Related Contents:
- Is there a way to ordinate numbers in a list?
- finding the biggest sequence of repeating numbers in a list
- How to append new line to the list
- Remove duplicate dict in list in Python
- How to efficiently compare two unordered lists (not sets) in Python?
- Finding max value in the second column of a nested list?
- Why does foo.append(bar) affect all elements in a list of lists?
- Filtering a list of strings based on contents
- Convert tuple to list and back
- Unpacking a list / tuple of pairs into two lists / tuples
- Python 3 turn range to a list
- Call int() function on every list element?
- Split list into smaller lists (split in half)
- Find nearest indices for one array against all values in another array – Python / NumPy
- Splitting on last delimiter in Python string?
- Transform “list of tuples” into a flat list or a matrix
- Inserting a value into all possible locations in a list
- Convert string to list. Python [string.split() acting weird]
- How do you split reading a large csv file into evenly-sized chunks in Python?
- Make dictionary from list with python [duplicate]
- Find the index of an item in a list of lists
- Slicing list of lists in Python
- Replacing a sublist with another sublist in python
- How to get the cartesian product of multiple lists
- How do I return dictionary keys as a list in Python?
- Why can’t I use a list as a dict key in python? Exactly what can and cannot be used, and why?
- Union find implementation using Python
- Check if all values in list are greater than a certain number
- Creating a list in Python with multiple copies of a given object in a single line
- Python : how to append new elements in a list of list?