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

Andy McKay andym at ActiveState.com
Sat Jul 21 19:18:50 CEST 2001


Tim Peters wrote a good recipe to do just that:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560

Cheers.
--
  Andy McKay.


----- Original Message ----- 
From: <gradha at iname.com>
Newsgroups: comp.lang.python
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?


> 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
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list