[Tutor] Looking for duplicates within a list
alan.gauld at btinternet.com
Fri Jun 11 16:58:19 CEST 2010
"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?
counts = set(( item, mylist.count(item)) for item in mylist if
mylist.count(item) > 1)
Seems to work...
Author of the Learn to Program web site
More information about the Tutor