python - Iterating through a dictionary and subtracting values based on keys -
so have dictionary 1 below, however, trying subtract art[0][0] - art[1][0] , has iteration.
this have, doesn't seem work. keep getting error: 'keyerror: 2'
any appreciated.
in range(1, 5): #from k = j in range (1, 5): #to if == j: pass else: t = art[j][0] - art[i][0] g = art[j][1] - art[i][1] sample input:
art = {'u': (5, 6), 'e': (7, 3), 'a': (3, 3), 'o': (3, 2), 'i': (1, 4)}
dictionaries accessed key name. see here examples.
for example, art['u'] return (5, 6). in code, you're trying access key 2, because that's j equal to. however, there no key named 2 in dictionary.
Comments
Post a Comment