I am iterating through the keys of one dictionary, finding the same key in a second dictionary, then trying to produce the first value of the list associated with the key in the second dictionary. When I look directly into the second dictionary it works fine:
Code:
for data in hud_data.get('veh_1'):
print(data[0])
Returns: 17.3245
This is correct. But when I try to run through all of the keys of hud_data by referencing the keys of another dictionary (UAV_data), I get a strange result:
Code:
for a_key in UAV_dict.keys():
# print(a_key)
for data in hud_data.get(a_key):
print(data[0])
break
This should produce the exact same thing. The first key in UAV_dict is 'veh_1', so when the second for loop runs, it should just return the same thing, 17.3245. Instead it returns all of the values for every key:
Return: 17.3245 19.3003 22.2483 29.8077 35.86
Why are all of the values for every key showing up in the output? How should I re-write the code so that it only produces the first outcome?