I've been trying to process data stored in a list of dictionaries, and store it in another list of tuples. For example say i have the following data:
triangles= [{"name": "triangle1", "base":3, "height":4},
{"name": "triangle2", "base":5, "height":12},
{"name": "triangle3", "base":8, "height":15}
]
And I want to run all the data through the following function which i cannot change:
def hypotenuse(base, height):
hyp_sq=base**2+height**2
return hyp_sq**(1.0/2.0)
Ideally, after computing all the data, I want to sort the triangles based on their hypotenuse length and I want to return a list of tuples in the following format:
hypotenuse_results=[("triangle1", 5), ("triangle2", 13), ("triangle3", 17)]
I know I have to use the map() function in conjunction with sorted() but I have no idea how to pass only the values corresponding to "base" and "height" keys.
If someone could point me in the right direction, it would be greatly appreciated.
Thanks