My dictionary with tuple as a key is as follows:
Key represents the x and y coordinates. (x, y)
D1 = {(10,12): 23, (8,14): 45, (12, 9): 29}
D2 = {(2, 8) : 67, (12, 10): 23, (14, 8): 56}
Now, from the above Dictionary, I would like to perform the following
- Sort dictionary D1 based on Keys
- Sort dictionary D2 based on Keys
- Simply, print the keys and values in D1
- Simply, print the keys and values in D2
- Then do the following:
(pseudocode)
total = 0
For each key (x, y) in D1,
if D2.has_key((y, x)):
total = total + D1[(x, y)] * D2[(y, x)]
Print total