lundi 29 juillet 2019

updating dictionary with a random nested dictionary

I have a program, however, I need to update the dict with a random key (the key is a nested dict). However, whenever I do, It gives me an error.

I have tried to use the .update, and used random.choice(dict), however this does nothing but give an error

dictA = { 1 : 2, 2 : 3, 3 : 4}
dictB = {}
dictB.update(random.choice(list(dictA)))

I excpet dictB to have a random key, however what I get is ValueError: dictionary update sequence element #0 has length 1; 2 is required




Aucun commentaire:

Enregistrer un commentaire