Re: Need help in understanding a python code

2008-11-17 Thread Steven D'Aprano
On Sun, 16 Nov 2008 04:34:40 -0800, John Machin wrote: > Nothing to do with style. It was the screaming inefficiency of: >if non_trivial_condition: return x >if not non_trivial_condition: return y > that fired me up. "Screaming inefficiency"? Try "micro-optimization". The difference in e

Re: Need help in understanding a python code

2008-11-16 Thread alex23
On Nov 17, 11:40 am, Matt Nordhoff <[EMAIL PROTECTED]> wrote: > That study has been disputed; see the links at the top of > . Now, if there was any independent refutation of the original study that isn't based on Britannica's - not that I'm ou

Re: Need help in understanding a python code

2008-11-16 Thread Matt Nordhoff
Benjamin Kaplan wrote: > If you really believe that, you haven't been following this list long > enough. Every terminology dispute always includes at least 1 Wikipedia > link. > > Also, you might want to look at this study: > http://news.cnet.com/2100-1038_3-5997332.html That study has been dispu

Re: Need help in understanding a python code

2008-11-16 Thread Benjamin Kaplan
On Sun, Nov 16, 2008 at 7:34 AM, John Machin <[EMAIL PROTECTED]> wrote: > On Nov 16, 11:04 pm, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: > > On Sun, 16 Nov 2008 02:41:03 -0800, John Machin wrote: > > > On Nov 16, 9:31 pm, Steven D'Aprano <[EMAIL PROTECTED] > > > cybersource.c

Re: Need help in understanding a python code

2008-11-16 Thread alex23
On Nov 17, 5:26 am, George Sakkis <[EMAIL PROTECTED]> wrote: > When quoting wikipedia became the new Godwin's law ?? :) Probably at the point the editors started becoming revisionists and culling anything they didn't consider notable enough. -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help in understanding a python code

2008-11-16 Thread George Sakkis
On Nov 16, 7:34 am, John Machin <[EMAIL PROTECTED]> wrote: > On Nov 16, 11:04 pm, Steven D'Aprano <[EMAIL PROTECTED] > > >http://en.wikipedia.org/wiki/Style_over_substance_fallacy > > Quoted Wikipedia -> instant disqualification -> you lose. Good night. When quoting wikipedia became the new Godwin

Re: Need help in understanding a python code

2008-11-16 Thread John Machin
On Nov 16, 11:04 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sun, 16 Nov 2008 02:41:03 -0800, John Machin wrote: > > On Nov 16, 9:31 pm, Steven D'Aprano <[EMAIL PROTECTED] > > cybersource.com.au> wrote: > >> On Sun, 16 Nov 2008 01:50:16 -0800, John Machin wrote: > >> > >

Re: Need help in understanding a python code

2008-11-16 Thread Steven D'Aprano
On Sun, 16 Nov 2008 02:41:03 -0800, John Machin wrote: > On Nov 16, 9:31 pm, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: >> On Sun, 16 Nov 2008 01:50:16 -0800, John Machin wrote: >> > > def A(w, v, i,j): >> > >     if i == 0 or j == 0: return 0 >> > >     if w[i-1] > j:  return

Re: Need help in understanding a python code

2008-11-16 Thread John Machin
On Nov 16, 9:31 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sun, 16 Nov 2008 01:50:16 -0800, John Machin wrote: > > > def A(w, v, i,j): > > >     if i == 0 or j == 0: return 0 > > >     if w[i-1] > j:  return A(w, v, i-1, j) > > >     if w[i-1] <= j: return max(A(w,v, i-1

Re: Need help in understanding a python code

2008-11-16 Thread Steven D'Aprano
On Sun, 16 Nov 2008 01:50:16 -0800, John Machin wrote: > > def A(w, v, i,j): > >     if i == 0 or j == 0: return 0 > >     if w[i-1] > j:  return A(w, v, i-1, j) > >     if w[i-1] <= j: return max(A(w,v, i-1, j), v[i-1] + > > A(w,v, i-1, j - w[i-1])) >> I am reading this blog >> >> http:/

Re: Need help in understanding a python code

2008-11-16 Thread John Machin
On Nov 16, 4:15 pm, "Meryl Silverburgh" <[EMAIL PROTECTED]> wrote: > This is the full source code: > def A(w, v, i,j): >     if i == 0 or j == 0: return 0 >     if w[i-1] > j:  return A(w, v, i-1, j) >     if w[i-1] <= j: return max(A(w,v, i-1, j), v[i-1] + A(w,v, i-1, j - > w[i-1])) Huh??? There

Re: Need help in understanding a python code

2008-11-15 Thread bearophileHUGS
silverburgh: > max([(sum(a[j:i]), (j,i)) Other people have already answered you so I'll add only a small note: today the max() function has a key optional attribute, so that code can also be written as: max(((j, i) for ...), key=lambda (j, i): sum(a[j : i])) I think you have copied that part fro

Re: Need help in understanding a python code

2008-11-15 Thread Aaron Brady
See below. On Nov 15, 11:15 pm, "Meryl Silverburgh" <[EMAIL PROTECTED]> wrote: > This is the full source code: > def A(w, v, i,j): >     if i == 0 or j == 0: return 0 >     if w[i-1] > j:  return A(w, v, i-1, j) >     if w[i-1] <= j: return max(A(w,v, i-1, j), v[i-1] + A(w,v, i-1, j - > w[i-1]))

Re: Need help in understanding a python code

2008-11-15 Thread Meryl Silverburgh
This is the full source code: def A(w, v, i,j): if i == 0 or j == 0: return 0 if w[i-1] > j: return A(w, v, i-1, j) if w[i-1] <= j: return max(A(w,v, i-1, j), v[i-1] + A(w,v, i-1, j - w[i-1])) I am reading this blog http://20bits.com/articles/introduction-to-dynamic-programming/ On

Re: Need help in understanding a python code

2008-11-15 Thread John Machin
On Nov 16, 3:41 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to understand the following line: > # a is an integer array > > max([(sum(a[j:i]), (j,i)) > > Can you please tell me what that means, > I think sum(a[j:i] means find the some from a[j] to a[i] > But what is the

Re: Need help in understanding a python code

2008-11-15 Thread Chris Rebert
On Sat, Nov 15, 2008 at 8:41 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to understand the following line: > # a is an integer array > > max([(sum(a[j:i]), (j,i)) This code isn't valid. You have a [ with no closing ]. Cheers, Chris -- Follow the path of the Iguana... h

Need help in understanding a python code

2008-11-15 Thread [EMAIL PROTECTED]
Hi, I am trying to understand the following line: # a is an integer array max([(sum(a[j:i]), (j,i)) Can you please tell me what that means, I think sum(a[j:i] means find the some from a[j] to a[i] But what is the meaning of the part (j,i)? -- http://mail.python.org/mailman/listinfo/python-list