How do I select all the timing together with the name of the point at which the time occurs from a dictionary?

Viewed 27

This is a section of the dictionary:

{'WayPoint46_WayPoint39': [(14.547985, datetime.datetime(2016, 5, 23, 18, 45, 47), True)], 'WayPoint39_WayPoint38': [(7.208904, datetime.datetime(2016, 5, 23, 18, 46, 13), True)], ... }

I want to select for example, WayPoint46_WayPoint39, 14.547985.

Thanks for helping in advance.

1 Answers

Probably the simpliest solution:

for key, value in input_dict.items():
    print(key, value[0][0])

With input_dict equal to your input, the output looks like:

WayPoint46_WayPoint39 14.547985
WayPoint39_WayPoint38 7.208904

For sum you can use sum() function:

print(sum([value[0][0] for value in input_dict.values()]))
Related