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 =
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
... 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
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 =
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
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
--
david jensen dmj@gmail.com 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
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]]
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
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,
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
11 matches
Mail list logo