[Tutor] Looking for duplicates within a list [SOLVED]
Ken G.
beachkid at insightbb.com
Fri Jun 11 17:19:17 CEST 2010
Alan Gauld wrote:
>
> "Ken G." <beachkid at insightbb.com> wrote
>
>> In any event, if a number is listed more than once, I would like to
>> know how many times, such as 2 or 3 times. For example, '3' is
>> listed twice within a list.
>
> 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)
>
> Seems to work...
>
> HTH,
>
>
Whee, this is great! I learned a lot today. Back to playing and studying.
Ken
More information about the Tutor
mailing list