Smarter way of doing this?
Phil Hornby
phil.hornby at accutest.co.uk
Mon Feb 2 08:41:22 EST 2004
Max,
Why not try something like:
prob_and_val = [[0.66,'item 1'],[0.33,'item 2'],[0.16,'item 3']]
Then access the probability of the first value
prob_and_val[0][0]
the second
prob_and_val[1][0]
and so on...
then you function 'choose_by_probability()'
could return the item instead of the index...
say like this for the first item
return prob_and_val[0][1]
could be called like below:
print choose_by_probability( prob_and_val )
HTH
--
Phil
"Requirements - what are they I just hack something together that does what
I think they want" ;)
More information about the Python-list
mailing list