Question: Part 2: Create a function sort by_total_calories. This function takes a single parameter that's a dictionary defined as follows data = { applescount: 12, calories:
Part 2: Create a function sort by_total_calories. This function takes a single parameter that's a dictionary defined as follows data = { "apples""count": 12, "calories": 200) pears": count": 2,"calories": 100) bananas" "count": 5, "calories": 300 The function returns a list of tuples. The first element of the tuple is the key (e.g. "apple") and the second element is the total calories (count calories). So the function sort by_total_calories() returns the list in descending order of total calories for each item. For the above data, the returned list would be:('apples', 2400), 'bananas', 1500),("pears, 200) def sort by_total_calories(v) vis a dictionary containing # {"key": {"count": int, "calories": int), out [ sorts v by total calories (calories * count) returns a list of the tuples in ascending order # each tuple is an item of the dictionary return out
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
