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

2010-03-17 Thread nn
Michael Torrie wrote: > david jensen wrote: > > 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

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 Michael Torrie
david jensen wrote: > 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+amount

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 Paul Rubin
david jensen writes: > Obviously, i can just write the code again, in an else, switching > indices 0 and 1. Or, I could just have a test at the beginning, switch > them if they are in the order "big, small", and then switch them again > at the end in a list comprehension. Both ideas seem terribly

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 Gerard Flanagan
david jensen wrote: ... 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]] abstracting the given algorithm: def iterweights(N): d = 1.0/(N-1) for i in xrange(N): yield i*d, (N-1-i)*d def iterpart

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

2010-03-16 Thread nn
david jensen wrote: > ... 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]] For starters: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder

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