Re: maximum() efficency

2006-03-27 Thread Steve R. Hastings
On Mon, 27 Mar 2006 07:50:01 -0800, Arne Ludwig wrote: > Just for completeness: The functions in Steve's original post named > maximum calculate the minimum. Er, yes. I benchmarked them but clearly I should have function-tested them as well. Here is, I hope, my last word on maximum(). It figu

Re: maximum() efficency

2006-03-27 Thread Paul McGuire
"Arne Ludwig" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Just for completeness: The functions in Steve's original post named > maximum calculate the minimum. > > Also, timing-wise, on my machine with a random list of 20 integers > Steve's iteration version and Mitja's version

Re: maximum() efficency

2006-03-27 Thread Arne Ludwig
Just for completeness: The functions in Steve's original post named maximum calculate the minimum. Also, timing-wise, on my machine with a random list of 20 integers Steve's iteration version and Mitja's version are about equal, the system built-in is equal or slightly slower, and Paul's versi

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
On Mon, 27 Mar 2006 00:11:04 +, Paul McGuire wrote: > The doc string is not correct. The fault is mine, I'm afraid. I had thought I was copying that from an intact original version, but I must have edited it. I don't remember doing it, but I must have. To check, I went to Sourceforge and do

Re: maximum() efficency

2006-03-26 Thread Steven Bethard
Steve R. Hastings wrote: > On Sun, 26 Mar 2006 10:34:16 -0700, Steven Bethard wrote: >> What's the original? > > def minimum(cmp, lst): > """minimum(cmp, lst) > > Returns the minimal element in non-empty list LST with elements > compared via CMP() which should return values with the same se

Re: maximum() efficency

2006-03-26 Thread Paul McGuire
"Steve R. Hastings" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Sun, 26 Mar 2006 10:34:16 -0700, Steven Bethard wrote: > > What's the original? > > > > def minimum(cmp, lst): > """minimum(cmp, lst) > > Returns the minimal element in non-empty list LST with elements > comp

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
Actually, now that I think about it, the version using iter() has one advantage over your version: it will work correctly if passed either a list or an iterator. So, for versions of Python that have iterators, I'd use the iter() version, but for older versions of Python, I'd use your version. P.S

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
On Sun, 26 Mar 2006 10:34:16 -0700, Steven Bethard wrote: > What's the original? def minimum(cmp, lst): """minimum(cmp, lst) Returns the minimal element in non-empty list LST with elements compared via CMP() which should return values with the same semantics as Python's cmp(). If there

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
On Sun, 26 Mar 2006 20:34:28 +0200, Mitja Trampus wrote: > I would have done it in the same way, but probably without the iterators. > I.e., like this: > > def maximum(lst): > try: m = lst[0] > except (TypeError, IndexError): raise Exception "Non-sequence or empty > sequence given to

Re: maximum() efficency

2006-03-26 Thread Paul McGuire
"Steve R. Hastings" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I was looking at a Python function to find the maximum from a list. > The original was more complicated; I simplified it. The built-in max() > function can replace the simplified example, but not the original. > > If

Re: maximum() efficency

2006-03-26 Thread Mitja Trampus
Steve R. Hastings wrote: > I was looking at a Python function to find the maximum from a list. > The original was more complicated; I simplified it. The built-in max() > function can replace the simplified example, but not the original. But you forgot to shuw us the original... [snip several im

Re: maximum() efficency

2006-03-26 Thread Steven Bethard
Steve R. Hastings wrote: > I was looking at a Python function to find the maximum from a list. > The original was more complicated; I simplified it. The built-in max() > function can replace the simplified example, but not the original. What's the original? Are you sure max can't solve it with

maximum() efficency

2006-03-26 Thread Steve R. Hastings
I was looking at a Python function to find the maximum from a list. The original was more complicated; I simplified it. The built-in max() function can replace the simplified example, but not the original. def maximum(lst): maxval = lst[0] for i in xrange(1, len(lst)): v = lst[i] i