[Tutor] Looking for duplicates within a list
Alan Gauld
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?
Something like:
counts = set(( item, mylist.count(item)) for item in mylist if
mylist.count(item) > 1)
Seems to work...
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list