[Tutor] Looking for duplicates within a list [SOLVED]

Ken G. beachkid at insightbb.com
Fri Jun 11 19:53:54 CEST 2010


davidheiserca at gmail.com wrote:
> How about this?
>  
> List = [1, 2, 3, 3, 3, 4, 5, 5]
> for Item in list(set(List)):
>     print Item, List.count(Item)
>  
>  
>
>     ----- Original Message -----
>     *From:* Ken G. <mailto:beachkid at insightbb.com>
>     *To:* Steven D'Aprano <mailto:steve at pearwood.info>
>     *Cc:* tutor at python.org <mailto:tutor at python.org>
>     *Sent:* Friday, June 11, 2010 9:09 AM
>     *Subject:* Re: [Tutor] Looking for duplicates within a list [SOLVED]
>
>
>     Steven D'Aprano wrote:
>>     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.
>>       
>     Hee, hee.  Will investigate further.  Thanks.
>
>     Ken
>         
>
>     ------------------------------------------------------------------------
>     ___
>
Oh, a nice one.  Many thanks.

Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100611/729e4f05/attachment.html>


More information about the Tutor mailing list