Question
#Create function called sort_artists. sort_artists will take as input a list of tuples. Each tuple will have two items: the first item will be a
#Create function called sort_artists. sort_artists will take as input a list of tuples. Each tuple will have two items: the first item will be a string holding an artist's name, and the second will be an integer representing their total album sales (in millions).
Return a tuple of two lists. The first list in the resulting tuple should be all the artists sorted alphabetically. The second list should be all the revenues sorted in descending numerical order.
For example:
artists = [("The Beatles", 270.8), ("Elvis Presley", 211.5), ("Michael Jackson", 183.9)]
sort_artists(artists) -> (["Elvis Presley", "Michael Jackson", "The Beatles"], [270.8, 211.5, 183.9])
Notice that artists is a list of tuples (brackets first,then parentheses), but sort_artists outputs a tuple of
lists (parentheses first, then brackets).
Add function here!
Below are some lines of code that will test your function.You can change the value of the variable(s) to test your function with different inputs.
If your function works correctly, this will originally
print:
(['Elvis Presley', 'Michael Jackson', 'The Beatles'], [270.8, 211.5, 183.9])
artists = [("The Beatles", 270.8), ("Elvis Presley", 211.5), ("Michael Jackson", 183.9)]
print(sort_artists(artists))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the sortartists function that sorts artists alphabetically and their revenues in d...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