Le 10/02/12 21:48, Thomas Philips a écrit :
Not a good example, with reversed(), you're not iterating on the list x but on an another list.Thanks for the insight. I saw the behavious as soon as I extended x with a bunch of 0'sx = list(range(10)) x.extend([0]*10) x[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]for i in reversed(x):if i % 2 == 0: x.remove(i)x[1, 3, 5, 7, 9]x = list(range(10)) x.extend([0]*10) x[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]for i in x:if i % 2 == 0: x.remove(i)x[1, 3, 5, 7, 9, 0, 0, 0, 0, 0] More precisely a 'listreverseiterator object. |
-- http://mail.python.org/mailman/listinfo/python-list