Re: [Tutor] Efficiency

2011-06-25 Thread Steven D'Aprano
Hello Naheed, You seem to have messed up your quoting. Text starting with a > is a quote, but in your reply, you have written text starting with > as if it were written by me. I have fixed the quoting in this reply, but please try to watch that. See below for more comments. naheed arafat w

Re: [Tutor] Efficiency

2011-06-25 Thread naheed arafat
On Sat, Jun 25, 2011 at 9:42 PM, Steven D'Aprano wrote: > naheed arafat wrote: > >> 1) >> >>> zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) > [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] >> >>> map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am > fine.'

Re: [Tutor] Efficiency

2011-06-25 Thread naheed arafat
On Sat, Jun 25, 2011 at 9:38 PM, Alan Gauld wrote: > > "naheed arafat" wrote > > 1) >> >>> zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) > [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] >> >>> map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am > fine.'.

Re: [Tutor] Efficiency

2011-06-25 Thread Peter Otten
naheed arafat wrote: > Is there any way easier to do the following? > input: > 'How are you' > 'I am fine' > output: > 'you I are am How fine' > > solution: ' '.join(reduce(lambda x,y:x+y, zip('How are you'.split(' ')[::-1], > 'I am fine'.split(' ' reversed(items) instead of items[::-1]

Re: [Tutor] Efficiency

2011-06-25 Thread Alexandre Conrad
2011/6/25 naheed arafat : > 1) zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) > [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) > [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] > > Which on

Re: [Tutor] Efficiency

2011-06-25 Thread Steven D'Aprano
naheed arafat wrote: 1) zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] Which one has better efficiency

Re: [Tutor] Efficiency

2011-06-25 Thread Alan Gauld
"naheed arafat" wrote 1) zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] Which one has better efficie

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Steven D'Aprano
Shane O'Connor wrote: Hi, First-time poster here. I've a question about loop efficiency - I was wondering whether this code: i = 0 while i < 1000: do something i+=1 is more efficient than: for i in range(1000): do something or: for i in xrange(1000): do something You can

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Andre Engels
On Thu, Mar 17, 2011 at 8:45 AM, Stefan Behnel wrote: > Note that a web application involves many things outside of your own code > that seriously impact the performance and/or resource requirements. Database > access can be slow, excessively dynamic page generation and template engines > can bec

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Stefan Behnel
Shane O'Connor, 17.03.2011 01:32: In particular, I'm using Python 2.4.3 on a web server which needs to run as fast as possible using as little memory as possible (no surprises there!). Note that a web application involves many things outside of your own code that seriously impact the performan

Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Alan Gauld
"Shane O'Connor" wrote First-time poster here. I've a question about loop efficiency - I was wondering whether this code: i = 0 while i < 1000: do something i+=1 is more efficient than: for i in range(1000): do something It is impossible to tell and 99% of the time irrelevant si

Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Corey Richardson
On 03/16/2011 08:32 PM, Shane O'Connor wrote: > Hi, > > First-time poster here. I've a question about loop efficiency - I was > wondering whether this code: > > i = 0 > while i < 1000: > do something > i+=1 > > is more efficient than: > > for i in range(1000): > do something > > or

Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Wayne Werner
On Wed, Mar 16, 2011 at 7:32 PM, Shane O'Connor wrote: > Hi, > > First-time poster here. I've a question about loop efficiency - I was > wondering whether this code: > > i = 0 > while i < 1000: > do something > i+=1 > > is more efficient than: > > for i in range(1000): > do something >

Re: [Tutor] Efficiency and speed

2010-03-22 Thread Alan Gauld
"James Reynolds" wrote On that end, I'm almost done readying "beginning Python: From Novice to Professional" Can anyone recommend anything else for me to read after that? I'm not familiar with that book but I'd say consider what area of programming you are interested in and get a specialist

Re: [Tutor] Efficiency and speed

2010-03-21 Thread James Reynolds
On Sat, Mar 20, 2010 at 1:17 PM, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 05:47:45 am James Reynolds wrote: > > > This is a monte-carlo simulation. > > > > The simulation measures the expiration of something and those > > somethings fall into bins that are not evenly dispersed. These bins > >

Re: [Tutor] Efficiency and speed

2010-03-20 Thread Steven D'Aprano
On Sat, 20 Mar 2010 05:47:45 am James Reynolds wrote: > This is a monte-carlo simulation. > > The simulation measures the expiration of something and those > somethings fall into bins that are not evenly dispersed. These bins > are stored in the nx list mentioned previously. > > So let's say you h

Re: [Tutor] Efficiency and speed

2010-03-20 Thread Steven D'Aprano
On Sat, 20 Mar 2010 03:41:11 am James Reynolds wrote: > I've still been working towards learning the language, albeit slowly > and I've been working on a project that is somewhat intense on the > numerical calculation end of things. > > Running 10,000 trials takes about 1.5 seconds and running 100

Re: [Tutor] Efficiency and speed

2010-03-20 Thread Dave Angel
(Please don't top-post. It ruins the context for anyone else trying to follow it. Post your remarks at the end, or immediately after whatever you're commenting on.) James Reynolds wrote: Here's another idea I had. I thought this would be slower than then the previous algorithm because it has

Re: [Tutor] Efficiency and speed

2010-03-19 Thread Stefan Behnel
James Reynolds, 19.03.2010 21:17: Here's another idea I had. I thought this would be slower than then the previous algorithm because it has another for loop and another while loop. I read that the overhead of such loops is high, so I have been trying to avoid using them where possible. Prematur

Re: [Tutor] Efficiency and speed

2010-03-19 Thread Alan Gauld
"James Reynolds" wrote Here's another idea I had. I thought this would be slower than then the previous algorithm because it has another for loop and another while loop. I read that the overhead of such loops is high, so I have been trying to avoid using them where possible. Thats often t

Re: [Tutor] Efficiency and speed

2010-03-19 Thread Luke Paireepinart
On Fri, Mar 19, 2010 at 3:17 PM, James Reynolds wrote: > Here's another idea I had. I thought this would be slower than then the > previous algorithm because it has another for loop and another while loop. I > read that the overhead of such loops is high, so I have been trying to avoid > using th

Re: [Tutor] Efficiency and speed

2010-03-19 Thread James Reynolds
Here's another idea I had. I thought this would be slower than then the previous algorithm because it has another for loop and another while loop. I read that the overhead of such loops is high, so I have been trying to avoid using them where possible. def mcrange_gen(self, sample): nx

Re: [Tutor] Efficiency and speed

2010-03-19 Thread Alan Gauld
"James Reynolds" wrote I've made a few other optimizations today that I won't be able to test until I get home, but I was wondering if any of you could give some general pointers on how to make python run a little more quickly. Always, always, get the algorithm efficient before trying to mak

Re: [Tutor] Efficiency and speed

2010-03-19 Thread Emile van Sebille
On 3/19/2010 9:41 AM James Reynolds said... OK, so starting here: def mcrange_gen(self, sample): lensample = len(sample) nx2 = self.nx1 nx2_append = nx2.append nx2_sort = nx2.sort nx2_reverse = nx2.reverse nx2_index = nx2.index nx2_remove = nx2.remove for s in ra

Re: [Tutor] Efficiency and speed

2010-03-19 Thread James Reynolds
Well, I'm always out to impress! This is a monte-carlo simulation. The simulation measures the expiration of something and those somethings fall into bins that are not evenly dispersed. These bins are stored in the nx list mentioned previously. So let's say you have the bins, a, b,c,d,e,f and yo

Re: [Tutor] Efficiency and speed

2010-03-19 Thread Stefan Behnel
James Reynolds, 19.03.2010 17:41: I've still been working towards learning the language, albeit slowly and I've been working on a project that is somewhat intense on the numerical calculation end of things. Running 10,000 trials takes about 1.5 seconds and running 100,000 trials takes 11 seconds

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Eric Brunson
Stephen McInerney wrote: > Kent, > > >>> I was asking if it's a recognized good programming practice to >>> declare and initialize *all* members in the class defn. >>> >> What do you mean by "initialize *all* members in the class defn"? >> > - obviously I meant to say do it in the __

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Kent Johnson
Stephen McInerney wrote: > Kent, > >>> I was asking if it's a recognized good programming practice to >>> declare and initialize *all* members in the class defn. >> >> What do you mean by "initialize *all* members in the class defn"? > - obviously I meant to say do it in the __init__() method, > I

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Stephen McInerney
Kent, I was asking if it's a recognized good programming practice to declare and initialize *all* members in the class defn. What do you mean by "initialize *all* members in the class defn"? - obviously I meant to say do it in the __init__() method, I wrote the snippet as I was rushing out th

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Alan Gauld
"Stephen McInerney" <[EMAIL PROTECTED]> wrote > I was asking if it's a recognized good programming practice to > declare and initialize *all* members in the class defn. > I think I'm hearing a general yes on that - any other opinions? It depends on what you mean by the class definition. In gen

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Kent Johnson
Stephen McInerney wrote: > I was asking if it's a recognized good programming practice to > declare and initialize *all* members in the class defn. What do you mean by "initialize *all* members in the class defn"? Your original example was not syntactically correct Python. You wrote: class C s

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Stephen McInerney
amming practice to declare and initialize *all* members in the class defn. I think I'm hearing a general yes on that - any other opinions? Stephen >From: Eric Brunson <[EMAIL PROTECTED]> >To: Alan Gauld <[EMAIL PROTECTED]> >CC: tutor@python.org >Subject: Re: [Tutor] E

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Eric Brunson
We're definitely on the same wavelength, Alan. :-) Alan Gauld wrote: > "Stephen McInerney" <[EMAIL PROTECTED]> wrote > > >> Eric, you misunderstood my point. >> I said you make a **token** assignment in the class defn simply >> to do two things: >> - 1) identify all the members in one place >

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Alan Gauld
"Stephen McInerney" <[EMAIL PROTECTED]> wrote > Eric, you misunderstood my point. > I said you make a **token** assignment in the class defn simply > to do two things: > - 1) identify all the members in one place > - 2) annotate each member's type, as much as you can I'm sure Eric can explain for

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Stephen McInerney
Eric, you misunderstood my point. I said you make a **token** assignment in the class defn simply to do two things: - 1) identify all the members in one place - 2) annotate each member's type, as much as you can e.g.: class C s = [] d = {} ot = (None, None) I didn't say you make the actual assign

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Alan Gauld
"Stephen McInerney" <[EMAIL PROTECTED]> wrote >>lines to parse in a Python project, typically only a third or a >>quarter of >>the number of lines - sometimes less than that. > > Can you cite us a literature source for saying that Python is 3-4x > more > expressive per line-of-code than C++? I

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Eric Brunson
Stephen McInerney wrote: > Hi Alan, > > >>> My friend clarifies: "It's not the efficiency of doxygen that's the >>> question. The problem is that you can add fields to objects as you go in >>> Python so you need to do a deep analysis of the code to determine the >>> >> class >> >>>

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Duncan Gibson
> Is this not just evidence of a very bad Python coding style? > Should we not always declare *all* class fields in the class definition > by assigning to them, even if the assignment is token or dummy > i.e. 'None', "", [], {} etc. this is one of the many things that pylint can warn you about. I

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Kent Johnson
Stephen McInerney wrote: > Hi Alan, > >>> My friend clarifies: "It's not the efficiency of doxygen that's the >>> question. The problem is that you can add fields to objects as you go in >>> Python so you need to do a deep analysis of the code to determine the >> class >>> structure which you don

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Stephen McInerney
Hi Alan, > > My friend clarifies: "It's not the efficiency of doxygen that's the > > question. The problem is that you can add fields to objects as you go in > > Python so you need to do a deep analysis of the code to determine the >class > > structure which you don't have to do with C++ (or Java

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Alan Gauld
"Stephen McInerney" <[EMAIL PROTECTED]> wrote > Yes but it's still a canonical question about analysis of > weakly-typed > dynamic languages, since my Java friend makes separate comments > about scalability when analyzing large builds - he claims 1-5m lines > of > code is a threshold. There is

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread ALAN GAULD
> My friend clarifies: "It's not the efficiency of doxygen that's the > question. The problem is that you can add fields to objects as you go in > Python so you need to do a deep analysis of the code to determine the class > structure which you don't have to do with C++ (or Java)." That's true

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-16 Thread Stephen McInerney
n Cameron <[EMAIL PROTECTED]> >CC: tutor@python.org >Subject: Re: [Tutor] Efficiency of Doxygen on Python vs C++? >Date: Thu, 16 Aug 2007 22:06:13 -0400 > >Kevin Cameron wrote: > > Stephen McInerney wrote: > >> My friend said the runtime efficiency of Doxygen on

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-16 Thread Kent Johnson
Kevin Cameron wrote: > Stephen McInerney wrote: >> My friend said the runtime efficiency of Doxygen on his build was much >> worse on the Python code than the C++ code, i.e. it took ages to parse >> the Python code. > It's not the efficiency of doxygen that's the question. The problem is > that yo

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-16 Thread Kevin Cameron
Stephen McInerney wrote: > My friend said the runtime efficiency of Doxygen on his build was much > worse on the Python code than the C++ code, i.e. it took ages to parse > the Python code. It's not the efficiency of doxygen that's the question. The problem is that you can add fields to objects as

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-16 Thread Stephen McInerney
My friend clarifies: "It's not the efficiency of doxygen that's the question. The problem is that you can add fields to objects as you go in Python so you need to do a deep analysis of the code to determine the class structure which you don't have to do with C++ (or Java)." He mentioned numbers

Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-16 Thread Alan Gauld
"Stephen McInerney" <[EMAIL PROTECTED]> wrote > My friend said the runtime efficiency of Doxygen on his build was > much > worse on the Python code than the C++ code, i.e. it took ages to > parse > the Python code. > > Anyone agree/disagree, or have any efficiency tips on how to > structure >