'list.pop inside a for loop doesn't pop the last elements [duplicate]

CODE :

stack = ['BOB','TOM','JAI','ALI','OM']
print(stack)

for i in stack:
    stack.pop()

print(stack)

OUTPUT :

['BOB', 'TOM', 'JAI', 'ALI', 'OM']
['BOB', 'TOM']

why does it stop after popping the last 3 elements? the list still has 2 elements left but it doesnt work for some reason



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source