Jul 24, 2018

Python sort example

>>> sorted([5, 2, 3, 1, 4])
[1, 2, 3, 4, 5]
>>> sorted([5, 2, 3, 1, 4], reverse=True)
[5, 4, 3, 2, 1]

sorted() takes two three parameters:

iterable - sequence (string, tuple, list) or collection (set, dictionary, frozen set) or any iterator 
reverse (Optional) - If true, the sorted list is reversed (or sorted in Descending order)
key (Optional) - function that serves as a key for the sort comparison