sorted key python

>>> sorted(student_tuples, key=itemgetter(2))
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

Here is what the above code is Doing:
1. The sorted() function takes a single argument which is the list to be sorted.
2. The sorted() function also takes a keyword argument key. The value of the key argument should be a function that takes a single argument and returns a key to use for sorting purposes.
3. The sorted() function will sort the list in ascending order by default. To sort the list in descending order, pass the reverse parameter as True.
4. The sorted() function returns a new sorted list.
5. The sorted() function is stable. This means that if two items have the same key, their original order is preserved.
6. The sorted() function is flexible. It can sort list of strings, list of tuples, list of objects, etc.
7. The sorted() function is fast. It’s a native Python function and it’s very efficient.
8. The sorted() function is a built-in function. You don’t need to import anything to use it.
9. The sorted() function is easy to use.