samedi 18 mars 2017

python: choose element from a list following a certain probability

I'm looking for a python function that would allow me, to given a list and a certain probability, return me only the element that "pass" the lottery. For instance:

my_list = ['A', 'B', 'C']
my_probability = 0.66
winner = THE_RANDOM_FUNCTION(my_list, my_probability)
print(winner)
>> ['A', 'C'] # Could be a different result but that only an example

Is there such function in the standard library or should I implement it?




Aucun commentaire:

Enregistrer un commentaire