So I am trying to combine two dictionaries with two similar keys. I read the post here in stack overflow about merging two dictionaries. However, when I ran it. It gives me an error of KeyError, even though I have all the keys in both dictionaries.
Here is the code:
coordinates={'hello': (2, 6), 'hola': (2, 6), 'hella': (2, 6), 'heya': (2, 6), 'heyo': (2, 6), 'hill': (2, 6), 'halo': (2, 6), 'hall': (2, 6), 'hail': (2, 6), 'hay': (2, 6), 'hale': (2, 6), 'holy': (2, 6)}
solution={'hello': 'right', 'hall': 'right', 'hella': 'left', 'hale': 'left', 'hail': 'down', 'heya': 'down', 'holy': 'down', 'hola': 'up', 'hay': 'down-right', 'hill': 'up-left', 'heyo': 'up-right', 'halo': 'down-left'}
FINAL_SOL = [coordinates, solution]
FINAL_DICT = {}
for word in coordinates.keys():
FINAL_DICT[word] = tuple(FINAL_DICT[word] for d in FINAL_SOL)
print(FINAL_DICT)
I was hoping to have a single dictionary with this format:
'Key': (x,y), direction
Please do help in what is making this error. Thanks!