I have a dictionary structure like the one shown below and I want to extract the "EV=5.0"
part from it. Just the first instance of it that is.
my_dict = {('zone1', 'pcomp100002', '33x75'): {('Dummy', 'EV=5.0', -5.0, -5.0, -5.0): 68.49582}, ('zone1', 'pcomp100004', '33x75'): {('Dummy', 'EV=5.0', -5.0, -5.0, -5.0): 37.59079}}
Note that the only thing I know is the structure of the dict
but not the actual master keys
(e.g., ('zone1', 'pcomp100002', '33x75')
) or sub keys
(e.g., ('Dummy', 'EV=5.0', -5.0, -5.0, -5.0
).
In other words, I know the location of the information I want to retrieve. Present in all sub keys
in position 1.
I came up with two ways to do it but I like neither of them:
# method 1 - unreadable
print(list(list(my_dict.values())[0].keys())[0][1])
# method 2 - two loops broken in their first iteration
for i in a.values():
for j in i:
print(j[1])
break
break
Converting the whole dict to string and seraching for "EV="
also occured to me but buit that was the ugliest thought I made in a long time.
Is there a better way that i am missing?