num_list = [1, 2, 3, 4, 5]
print(num_list)
i = 0
while i < len(num_list):
if num_list[i] == 2:
num_list.pop(i)
i -= 1
else:
print(num_list[i])
i += 1
print(num_list)
转载来源:https://www.cnblogs.com/bananaplan/p/remove-listitem-while-iterating.html