Re: Tough sorting problem: or, I'm confusing myself

2010-04-16 Thread Peter Otten
david jensen wrote: > Hi all, > > I'm trying to find a good way of doing the following: > > Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding > value n-tuple (call them "scores" for clarity later). I'm currently > storing them in a dictionary, by doing: > > > res={} >

Re: Tough sorting problem: or, I'm confusing myself

2010-04-16 Thread Lie Ryan
On 04/15/10 02:03, Paul Rubin wrote: > Raymond Hettinger writes: >> Not sure what the readability issue is. The phrase "nlargest(2, >> iterable)" does exactly what it says, finds the 2 largest elements >> from an iterable. That makes the programmer's intent more clear than >> the slower, but sem

Re: Tough sorting problem: or, I'm confusing myself

2010-04-15 Thread david jensen
On Apr 14, 6:06 pm, Raymond Hettinger wrote: > > I'm not sure a heap will help much, and at least to me, > > doesn't improve readability. > > nlargest() should save quite a few comparisons and run much faster > than sorted(). > > Not sure what the readability issue is.  The phrase "nlargest(2, > i

Re: Tough sorting problem: or, I'm confusing myself

2010-04-14 Thread Raymond Hettinger
> > Not sure what the readability issue is.  The phrase "nlargest(2, > > iterable)" does exactly what it says, finds the 2 largest elements > > from an iterable.  That makes the programmer's intent more clear than > > the slower, but semanticly equivalent form:  sorted(iterable)[:2]. > > I think yo

Re: Tough sorting problem: or, I'm confusing myself

2010-04-14 Thread Paul Rubin
Raymond Hettinger writes: > Not sure what the readability issue is. The phrase "nlargest(2, > iterable)" does exactly what it says, finds the 2 largest elements > from an iterable. That makes the programmer's intent more clear than > the slower, but semanticly equivalent form: sorted(iterable)[

Re: Tough sorting problem: or, I'm confusing myself

2010-04-14 Thread Raymond Hettinger
> I'm not sure a heap will help much, and at least to me, > doesn't improve readability. nlargest() should save quite a few comparisons and run much faster than sorted(). Not sure what the readability issue is. The phrase "nlargest(2, iterable)" does exactly what it says, finds the 2 largest ele

Re: Tough sorting problem: or, I'm confusing myself

2010-04-13 Thread david jensen
On Apr 12, 1:22 am, Paul McGuire wrote: > On Apr 9, 10:03 am, david jensen wrote: > > > > > Hi all, > > > I'm trying to find a good way of doing the following: > > > Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding > > value n-tuple (call them "scores" for clarity later). I'

Re: Tough sorting problem: or, I'm confusing myself

2010-04-13 Thread david jensen
On Apr 11, 9:39 pm, Raymond Hettinger wrote: > The overall algorithm looks about right. > The inner-loop could be tighted-up a bit. > And you could replace the outer sort with a heap. > > best2 = {} > for i in itertools.combinations(range( 2**m), n-1): >     scorelist = [] >     for j in range( 2

Re: Tough sorting problem: or, I'm confusing myself

2010-04-11 Thread Paul McGuire
On Apr 9, 10:03 am, david jensen wrote: > Hi all, > > I'm trying to find a good way of doing the following: > > Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding > value n-tuple (call them "scores" for clarity later). I'm currently > storing them in a dictionary, by doing: > >

Re: Tough sorting problem: or, I'm confusing myself

2010-04-11 Thread Raymond Hettinger
On Apr 9, 8:03 am, david jensen wrote: > Hi all, > > I'm trying to find a good way of doing the following: > > Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding > value n-tuple (call them "scores" for clarity later). I'm currently > storing them in a dictionary, by doing: > >

Tough sorting problem: or, I'm confusing myself

2010-04-09 Thread david jensen
Hi all, I'm trying to find a good way of doing the following: Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding value n-tuple (call them "scores" for clarity later). I'm currently storing them in a dictionary, by doing: res={} for i in itertools.combinations( range( 2**