<jupyter_start><jupyter_text>Sorting Lists of ListsSort the following list of lists by the grades in descending order. The desired output should be: [['Kaylee', 99], ['Simon', 99], ['Zoe', 85], ['Malcolm', 80], ['Wash', 79]]     Hints: https://wiki.python.org/moin/HowTo/Sorting<jupyter_code>grades = [["Malcolm", 80], ["Zoe", 85], ["Kaylee", 99], ["Simon", 99], ["Wash", 79]]<jupyter_output><empty_output><jupyter_text>Solution 1: Adding a Key to the sort<jupyter_code>sorted_grades = []

while grades:
    max_item = grades[0]
    for grade in grades: 
        if grade[1] > max_item[1]:
            max_item = grade
    sorted_grades.append(max_item)
    grades.remove(max_item) 
sorted_grades<jupyter_output><empty_output><jupyter_text>Solution 2: Sort by Key<jupyter_code>grades = [["Malcolm", 80], ["Zoe", 85], ["Kaylee", 99], ["Simon", 99], ["Wash", 79]]
sorted(grades, key=lambda x: x[1], reverse=True)<jupyter_output><empty_output><jupyter_text>Solution 3: itemgetter<jupyter_code>grades = [["Malcolm", 80], ["Zoe", 85], ["Kaylee", 99], ["Simon", 99], ["Wash", 79]]

from operator import itemgetter
sorted(grades, key=itemgetter(1), reverse=True)<jupyter_output><empty_output><jupyter_text>Solution 4: Decorate-Sort-Undecorate Patternhttps://wiki.python.org/moin/HowTo/Sorting<jupyter_code>grades = [["Malcolm", 80], ["Zoe", 85], ["Kaylee", 99], ["Simon", 99], ["Wash", 79]]
# Step 1) Create a sortable tuple using the grade
decorated = [(grade[1], grade) for grade in grades]
decorated
# Step 2) Sort the grade in descending order
decorated.sort(reverse=True)
decorated
# Step 3) Remove the decorated value
sorted_grades = [grade for (grade_num, grade) in decorated]
sorted_grades<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16744186046511628, 'fraction_numerical': 0.03662790697674419, 'mean_word_length': 6.323404255319149, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '110189', 'license': 'ADSL', 'n_tokens_mistral': 687, 'n_tokens_neox': 606, 'n_words': 157, 'path': '04-Career-Modules/Interview_Questions/01-Sort_List_of_Lists/Solved/Sort_List_of_Lists.ipynb', 'repo_name': 'anirudhmungre/sneaky-lessons', 'size': '1720'}