Thanks :) Alan
Steven Bethard wrote:
Well, this does about the same thing, but using enumerate and a list comprehension:
py> lst = [0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5] py> [item for i, item in enumerate(lst) if i == 0 or item != lst[i-1]] [0, 1, 2, 3, 2, 4, 5]
Similar code that doesn't check 'if i == 0' each time through:
py> itr = enumerate(lst) py> itr.next() (0, 0) py> [lst[0]] + [item for i, item in itr if item != lst[i-1]] [0, 1, 2, 3, 2, 4, 5]
I don't know if either of these is really more elegant though...
Steve
-- http://mail.python.org/mailman/listinfo/python-list