dimanche 17 décembre 2017

Find value of a randomly chosen key from dictionary

I have a .py dictionary which I want to use in another file. I want to randomly choose a key

w_keys = dictionary.dic.keys()

def inf():
   return random.choice(list(w_keys))

x = inf()

and then I need to find the value of the chosen key,

value = dictionary.dic.values()
return dictionary.dic[x] == value

but I am not sure how to do so and my attempts (unsurprisingly) don't work?




Aucun commentaire:

Enregistrer un commentaire