I'm trying to make a system where I take a value from a dictionary, and then attempt to find a value from a different dictionary with it. I've attempted this multiple times and have not been successful.
import random
dic = {
'1': 'hi',
'2': 'hi2',
}
dic2 = {
'1': 'hello',
'2': 'hello2',
}
x = random.choice(list(dic))
print(x)
y = dic2['x']
print(y)
This code is non-funcitonal and returns File "<PATH>", line 16, in <module> <y = dic2['x'] KeyError: 'x'
Aucun commentaire:
Enregistrer un commentaire