python pop in for loop code example
Example 1: 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']
Example 2: pop list python
#pop removes the last element
li=[1,2,3,4,5]
li.pop()
#>>>[1, 2, 3, 4]