question about for cycle
John Machin
sjmachin at lexicon.net
Sat Sep 29 09:01:26 EDT 2007
On Sep 29, 8:04 pm, "fdu.xia... at gmail.com" <fdu.xia... at gmail.com>
wrote:
[snip]
> And I have another question. Which is the most efficient way to check if there
> are duplicate items in a list ? The items in the list may cannot be hashed, so
> set() may not work on the list.
The following classic by Tim Peters answers the question "How do I
remove duplicate items from a list".
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
It should help -- provided of course that you mean "duplicates" in the
sense that two Python objects a and b are duplicates iff a == b.
If you mean duplicates in a fuzzier sense e.g. "Mao Zedong" and "Mao
Tse-Tung", the problem gets harder ...
HTH,
John
More information about the Python-list
mailing list