Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Draw a labelled diagram of the Dicot stem.

Answered: 1 week ago