How to randomly choose an item from a Python dictionary?

Asked

Viewed 1,868 times

5

I would like to know how to randomly choose an item from a Python dictionary?

For example:

I have the dictionary

dic = {'Pedro': 99, 'João': 19, 'Rosa': 35, 'Maria': 23}

and need to choose an item randomly.

  • By item you mean the key, the value or both?

  • Both key and value

1 answer

4


Browser other questions tagged

You are not signed in. Login or sign up in order to post.