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-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 > > valu

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

off by 1 error?

2010-04-09 Thread david jensen
Hi all, I'm trying to assign a color to various values between some arbitrary maximum and minimum, and i'd like to go from red to blue to green . Currently, I have the following, where i'm passing the minimum and maximum as a 2-tuple: def getcolor( minmax, curr ): rangesize = (minmax[1] -

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**

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
>If Gerard's code works, I would consider it far superior to your code >here. Pythonic does not necessarily mean short and ugly yes, I agree... and in my script i'm using something very like Gerard's (thanks again, Gerard). I just posted the corrected version of nn's because the original solved o

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
of course, changing nn's to: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder = myList[not low_id]-myList[low_id] tail=list(myList[2:]) outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ tail for perc i

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
Thanks Paul, but i don't immediately see how that helps (maybe I'm just being dense)... nn's solution, though i initially thought it worked, actually has a similar problem: intended: >>> print getOutcomes([3,4,5,5]) [[6, 1, 5, 5], [4.5, 2.5, 5, 5], [3, 4, 5, 5], [1.5, 5.5, 5, 5], [0, 7, 5, 5]] >>>

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
Thank you both very much! Yeah: it was a total brainfart on my part: nn's solution should have been obvious. As the general solution, i like your approach, Gerard, but I think I'll stick to nn's, the one i should have written. Again, thank you both! dmj -- http://mail.python.org/mailman/listin

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
... and of course i screwed up my outcomes... that should read outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] -- http://mail.python.org/mailman/listinfo/python-list

Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
Hi all, This may be a complete brainfart, but it's been puzzling me for a day or two (!). Sorry for not describing "something" in the subject, but it's hard to describe succinctly: I have a short list of non-zero positive integers (say myList=[2,5,8,3,5]). I need to return five lists of non-negat