Lets say I have the following Python list:
mylist = [
["name_a", "sex_male", "age_15", "grade_11"],
["name_b", "sex_male", "age_18", "grade_9"],
["name_c", "sex_male", "age_11", "grade_8"],
["name_d", "sex_male", "age_16", "grade_12"],
["name_e", "sex_male", "age_19", "grade_13"],
]
I want to call Python's sort() function to sort mylist by age
For instance, I want to do something like this:
mylist.sort(key=...)
to get the output
mylist = [
["name_c", "sex_male", "age_11", "grade_8"],
["name_a", "sex_male", "age_15", "grade_11"],
["name_d", "sex_male", "age_16", "grade_12"],
["name_b", "sex_male", "age_18", "grade_9"],
["name_e", "sex_male", "age_19", "grade_13"],
]
What is the right way to do this?
P.S
One more question: why sorting algorithm is used in Python's sort() function? (ex. QuickSort?)