[Tutor] Problems with Importing into the Python Shell

2010-06-11 Thread Andrew Martin
Hey, everyone, I am new to programming and just downloaded Python 2.6 onto my windows vista laptop. I am attempting to follow 4.11 of the tutorial called "How to Think Like a Computer Scientist: Learning with Python v2nd Edition documentation" ( http://openbookproject.net/thinkcs/python/english2e/c

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Steven D'Aprano
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

Re: [Tutor] Python a substitute/alternative for PhP?

2010-06-11 Thread Alex Hall
Personally, I would learn Python. My college does not offer Python either, so I had to learn what I know on my own(of course, by that I mean constantly pestering this and other of the amazing Python email lists). PHP is fine in itself, but, after using it, Java, and intros to a few other languages,

[Tutor] Python a substitute/alternative for PhP?

2010-06-11 Thread Eldon Londe Mello Junior
Hi there, If you care to listen to my story and fully help me out, just keep on reading }else{ move to the final question :) I'm just finishing an introductory course on PhP and MySQL (HTML, CSS and Javascript basics included). That's a typical first step to novice programmers in Brazil. H

Re: [Tutor] What's the catch with ZopeDB?

2010-06-11 Thread Dave Kuhlman
On Fri, Jun 11, 2010 at 09:42:35PM +0200, Knacktus wrote: > > To me, ZopeDB (a object database for Python) looks like an awesomely > easy solution. I could save some brain power for the innovative part or > drink more beer watching the soccer world cup. At the same moment, I > wonder why anyon

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Dave Kuhlman
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]

Re: [Tutor] What's the catch with ZopeDB?

2010-06-11 Thread Emile van Sebille
On 6/11/2010 12:42 PM Knacktus said... So, has anyone experience with ZopeDB? Are there some drawbacks I should be aware of before getting a book and dive in? (It sounds too good ;-)) I've been using it as part of a couple applications I wrote 10 years ago that use zope. I'm not sure how my

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Hugo Arts
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

[Tutor] What's the catch with ZopeDB?

2010-06-11 Thread Knacktus
Hey everyone, I'm planning to create small application which manages product data e.g. parts of cars. There are quite some relations, e.g. - a car consists of certain assemblies, - an assembly consists of certatin parts, - a part has serveral documents which describe the part, e.g. a CAD docum

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.
davidheise...@gmail.com wrote: 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:

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

2010-06-11 Thread Steven D'Aprano
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

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Steven D'Aprano
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

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 within

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Hugo Arts
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

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

2010-06-11 Thread Steven D'Aprano
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

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Dave Angel
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

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.

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Alan Gauld
"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

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Jose Amoreira
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

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Sander Sweers
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] >

Re: [Tutor] Looking for duplicates within a list

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

Re: [Tutor] Looking for duplicates within a list

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

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Alex Hall
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

[Tutor] Looking for duplicates within a list

2010-06-11 Thread Ken G.
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 containing the numbe