jeudi 24 décembre 2020

From a dictionary made of multiple lists choose one element from each

Lets say I have a dictionary of lists like this:

lists= {'pet': ["dog", "cat", "parrot"],
        'amount': [1,2,3],
        'food': ["canned", "dry"]}

And I want to pick one element from each list, randomly, so the result is like this:

{'amount': 2, 'food': 'canned', 'pet': 'cat'}

Which would the simplest way to achieve it using Python?




Aucun commentaire:

Enregistrer un commentaire