Question
Code in python 3: Question: The input of this function is a list of names and a list of corresponding scores. The function should return
Code in python 3:
Question:
The input of this function is a list of names and a list of corresponding scores. The function should return a list in descending order of the score Then if we have a tie score, the function should order the names alphabetically with the "smaller" string come first. example: pref_list(["Kate", "Jame", "John"], [9.2, 4.5, 9.2]) == ["Kate", "John", "Jame"]
In my code, I sorted the list by descending order of the scores, but how can I sort the names since the tie score occurs?
(please don't use the method like "key = lambda" or "key = itemgetter" to sort. It will be great to only use for loops, if-else statement, list, or dict)
1 def pref_list(names, pref): 2 3 4 if len (names) != len(pref): 5 return None 6 7 get_list = [[names[i], pref[i]] for i in range(len(names))] 8 9 10 1 = len(get_list) 11 for i in range(0, 1): 12 for j in range(0, l-i-1): 13 if get_list[j][1] = get_list [j + 1][1]: 14 tempo = get_list[j] 15 get_list[j]= get_list[j + 1] 16 get_list[j + 1]= tempo 17 18 print(get_list) 19 o co 20 21 if __name _main_": 22 pref_list( ["Kate","Jame", "John"], [9.2, 4.5, 9.2]) 23 [['Kate', 9.2], ['John', 9.2], ['Jame', 4.5]]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