I intended to remove the elements with '0'
in the end or only with '0'
, and my codes are:
s = ['a0', 'b0', '0', 'c', 'd']
for x in s:
if x[-1] == '0' or x == '0':
s.remove(x)
s #result
['b0', 'c', 'd']
When I debug, I found that after 'a0' is removed, the s
becomes ['b0', '0', 'c', 'd']
, then as I thought, x will be 'b0'
, but it turn out to be '0'
, so it skipps the 'b0'
, I am wondering the reason behind that and how to fix it?