Removal of element from list while traversing causes the next element to be skipped
Neil Cerutti
mr.cerutti at gmail.com
Wed Jan 30 08:04:18 EST 2008
On Jan 30, 2008 6:57 AM, Arnaud Delobelle <arnodel at googlemail.com> wrote:
> Or one could use the trick of counting from the right (untested):
>
> n = len(a)
> for i, x in enumerate(a):
> if x == 99: del a[i-n]
Or one can put on his bellbottoms, horn-rimmed glasses, and wear a mullet:
i = 0
while i < len(a):
if a[i] == 99:
del a[i]
else:
i += 1
--
Neil Cerutti <mr.cerutti+python at gmail.com>
More information about the Python-list
mailing list