[Tutor] how to remove the coming duplication

Peter Otten __peter__ at web.de
Thu Nov 10 09:37:22 CET 2011


Christian Witts wrote:

> def remove_coming_duplication(a_list):
>      return [element for idx, element in enumerate(a_list) if element !=
> a_list[idx-1]]

Beware of negative indices:

>>> remove_coming_duplication([1, 2, 1])
[2, 1] # should be [1, 2, 1]




More information about the Tutor mailing list