What's the best way to delete duplicated entries in a list?
andym at ActiveState.com
Sat Jul 21 13:18:50 EDT 2001
Tim Peters wrote a good recipe to do just that:
----- Original Message -----
From: <gradha at iname.com>
To: <python-list at python.org>
Sent: Saturday, July 21, 2001 6:54 AM
Subject: What's the best way to delete duplicated entries in a list?
> Given a list of strings, I am doing the following to delete duplicated
> x = 0
> while x < len (my_list) - 1:
> if my_list[x] == my_list[x+1]:
> del my_list[x+1]
> x = x + 1
> Is there some more elegant, fast, algorithm? Is this the only one
> obvious way to do it?
> Grzegorz Adam Hankiewicz gradha at terra.es http://gradha.infierno.org
More information about the Python-list