What's the best way to delete duplicated entries in a list?

Dieter Deyke Dieter_Deyke at CoCreate.com
Sat Jul 21 12:56:20 EDT 2001


How about:

tmp = {}
for x in my_list: tmp[x] = 1
my_list = tmp.keys()

gradha at iname.com writes:

> Hi.
>
> Given a list of strings, I am doing the following to delete duplicated
> entries:
>
> my_list.sort()
> x = 0
> while x < len (my_list) - 1:
>       if my_list[x] == my_list[x+1]:
>               del my_list[x+1]
>       else:
>               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

--
Dieter Deyke
mailto:Dieter_Deyke at CoCreate.com mailto:deyke at yahoo.com
Vs lbh pna ernq guvf, lbh unir jnl gbb zhpu gvzr.



More information about the Python-list mailing list