How to do sorting in python?
Basically there are two built-in functions you can use:
sort() is called from a list object (therefore only defined for lists) and modifies
the list in-place. If you don’t need the original list, this function is okay and slightly
sorted() on the other hand is more convenient and accepts any iterable. It does not
modify lists in-place, instead, it returns a new sorted list.
- More on sorting basics.