[Tutor] Looking for duplicates within a list
Steven D'Aprano
steve at pearwood.info
Fri Jun 11 17:49:54 CEST 2010
On Sat, 12 Jun 2010 12:58:19 am Alan Gauld wrote:
> Have you looked at the count method of lists?
>
> Something like:
>
> counts = set(( item, mylist.count(item)) for item in mylist if
> mylist.count(item) > 1)
That's a Shlemiel the Painter algorithm.
http://www.joelonsoftware.com/articles/fog0000000319.html
> Seems to work...
You say that now, but one day you will use it on a list of 100,000
items, and you'll wonder why it takes 45 minutes to finish, and curse
Python for being slow.
--
Steven D'Aprano
More information about the Tutor
mailing list