How's the key to the vocabulary?
-
Please give me some help with the vocabulary. There's a dictionary.
{'B': {'old': 60691.96, 'now': 61928.03, 'change': 2.04}, 'E': {'old': 4418.98, 'now': 4605.43, 'change': 4.22}, 'D': {'old': 188.5, 'now': 192.49, 'change': 2.12}} max_percent = 4.22
for xer in global_dict.values():
if xer['change'] == max_percent:
print(xer)
break
else:
continueConclusion
{'old': 4418.98, 'now': 4605.43, 'change': 4.22}
I need the key back with the vocabulary. I mean.
{'E': {'old': 4418.98, 'now': 4605.43, 'change': 4.22}}
The problem is, in order to find the key, we need to first turn to the elements of the meaning, compare to 4.2, and then, at this value, the key in the 'change', return the meaning of the dictionary in which it is.
-
in cycle instead
values()
Use it.items()
which contains information on the key and the meaning, not just the meaningglobal_dict = {'B': {'old': 60691.96, 'now': 61928.03, 'change': 2.04}, 'E': {'old': 4418.98, 'now': 4605.43, 'change': 4.22}, 'D': {'old': 188.5, 'now': 192.49, 'change': 2.12}} max_percent = 4.22
for xer in global_dict.items():
if xer[1]['change'] == max_percent:
print(xer)
break