Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python list .remove() in for loop breaks

elements = ['el1', 'el2', 'el3', 'el4', 'el5']
for el in elements[:]: #[:] shallow-copies the list
    if el.lower() in ['el2', 'el3', 'el4']:
        elements.remove(el)
// elements -> ['el1', 'el5']
 
PREVIOUS NEXT
Tagged: #python #list #loop #breaks
ADD COMMENT
Topic
Name
1+3 =