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

2010-06-11 Thread Alan Gauld
wrote How about this? List = [1, 2, 3, 3, 3, 4, 5, 5] for Item in list(set(List)): print Item, List.count(Item) Not bad and you don't need the convert back to list() But it doesn't filter out those items which are unique which the OP asked for. So I guess it becomes for item in set(L

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

2010-06-11 Thread Ken G.
.info> *Cc:* tutor@python.org <mailto:tutor@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 l

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

2010-06-11 Thread Ken G.
Hugo Arts wrote: On 11 jun 2010, at 17:49, 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

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

2010-06-11 Thread ALAN GAULD
> > counts = > > set(( item, mylist.count(item)) for item in mylist if mylist.count(item) > > Whee, this is great! I learned a lot today. I should have added that although thats a one liner in code terms it does involve iterating over the list twice - in count() - for each element. So it

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

2010-06-11 Thread davidheiserca
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. To: Steven D'Aprano Cc: tutor@python.org Sent: Friday, June 11, 2010 9:09 AM Subject: Re: [Tutor] Looking for duplicates w

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

2010-06-11 Thread Ken G.
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.joelons

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

2010-06-11 Thread Ken G.
Dave Angel wrote: Ken G. wrote: I have been working on this problem for several days and I am not making any progress. I have a group of 18 number, in ascending order, within a list. They ranged from 1 to 39. Some numbers are duplicated as much as three times or as few as none. I started

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

2010-06-11 Thread Ken G.
Alan Gauld wrote: "Ken G." 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

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

2010-06-11 Thread Ken G.
Jose Amoreira wrote: On Friday, June 11, 2010 02:57:34 pm Ken G. wrote: I have been working on this problem for several days and I am not making any progress. I have a group of 18 number, in ascending order, within a list. They ranged from 1 to 39. Some numbers are duplicated as much as th

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

2010-06-11 Thread Ken G.
Sander Sweers wrote: On 11 June 2010 15:57, Ken G. 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. If you do not have top keep the order of the number this will work.