I want to randomly select an animal and if there is no value 0 then decrease the value by 1. I want to repeat the action twice. Try:
animals = {
"pets": {"dog": 2, "cat": 1, "mouse": 0}}
a = random.choice(list(animals["pets"]))
but this only displays the name of the animal. I would like to get a result like this: dog 1, cat 0, mouse 0
How to do it? Thank you and best regards.
source https://stackoverflow.com/questions/75251242/how-to-randomly-pick-key-from-dict-and-change-valuehow-to-randomly-pick-key-and
Comments
Post a Comment