I have a dictionary that looks like this: {"one": 5, "two": 1, "three": 25, "four": 14}
I want to choose a key from the dictionary in proportion to the values, i.e. "three" would have the highest chance, then "four" then "one" and then "two". I've looked at this question however it seems to be specific to when the numbers add up to 1.
I've really no idea how to start, help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire