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 with one li
On Sat, 12 Jun 2010 05:59:45 am Hugo Arts wrote:
[...]
Putting aside all the theoretical arguments, and getting to an actual,
real-life example:
> > So somebody used an algorithm which they KNEW was inefficient and
> > slow, it had been there for years, affecting who knows how many
> > people, u
On Fri, Jun 11, 2010 at 09:57:34AM -0400, Ken G. wrote:
>
>
>for j in range (0, 5):
>x = a[0] # for example, 1
One picky, little point.
I've seen several solutions in this thread that included something
like the following:
for i in range(len(mylist)):
val = mylist[i]
I really shouldn't, but I'll bite just this once.
On Fri, Jun 11, 2010 at 7:28 PM, Steven D'Aprano wrote:
>
> Your idea of elegant and simple is not the same as mine. To me, I see
> unnecessary work and unneeded complexity. A generator expression for a
> beginner having trouble with the basics? C
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
.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
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
> > 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
On Fri, 11 Jun 2010 11: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 three times or as few as n
On Sat, 12 Jun 2010 02:18:52 am 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 myli
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
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 Shlemiel the P
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
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
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/fog00
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 with one list conta
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
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
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.
"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(item)) for item in
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
> three times or as few
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.
>>> a = [1, 2, 3, 3, 4]
>
Alex Hall wrote:
On 6/11/10, 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.
vijay wrote:
Check out this code
l= [1, 2, 3, 3, 4]
d={}
for item in l:
d.setdefaut(item,0)
d[item] +=1
print d
{1: 1, 2: 1, 3: 2, 4: 1}
with regard's
vijay
Thanks. Very interesting concept.
Ken
___
Tutor maillist - Tutor@python.or
On 6/11/10, 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.
FYI, Python's
25 matches
Mail list logo