Smarter way of doing this?
phil.hornby at accutest.co.uk
Mon Feb 2 14:41:22 CET 2004
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
and so on...
then you function 'choose_by_probability()'
could return the item instead of the index...
say like this for the first item
could be called like below:
print choose_by_probability( prob_and_val )
"Requirements - what are they I just hack something together that does what
I think they want" ;)
More information about the Python-list