Question
apples = { McIntosh: {sweetness: 3, tartness: 7}, Red Delicious: {sweetness: 5, tartness: 1}, Fuji: {sweetness: 8, tartness: 3}, Gala: {sweetness: 6, tartness: 1}, Ambrosia:
apples = { "McIntosh": {"sweetness": 3, "tartness": 7}, "Red Delicious": {"sweetness": 5, "tartness": 1}, "Fuji": {"sweetness": 8, "tartness": 3}, "Gala": {"sweetness": 6, "tartness": 1}, "Ambrosia": {"sweetness": 7, "tartness": 1}, "Honeycrisp": {"sweetness": 7.5, "tartness": 8}, "Granny Smith": {"sweetness": 1, "tartness": 10} }
def by_sweetness(tup): return tup[1]['sweetness']
1) Write a function called apple_sorting that has two parameters: data (the data model) and sort_helper (the function used to sort the model). The apple_sorting should use the sorted function to sort the data (e.g. data.items()) with sort_helper. The function returns a list of tuples in order of their sweetness (sweetest apples listed first).
Once done, this should work:
print(apple_sorting(apples, by_sweetness))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started