T
T
toshk92020-08-22 01:52:47
Python
toshk9, 2020-08-22 01:52:47

Is there a library/method in Python that takes a *random* element(key) from a given dictionary and writes it to a variable?

It is necessary that a random (important) key with its value from the given dictionary is taken, and the key value can be written to a separate variable and used later.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-08-22
@toshk9

well, the question

import random
d = {'VENEZUELA':'CARACAS', 'CANADA':'OTTAWA'}
random.choice(list(d.values()))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question