Ben Chuanlong Du's Blog

It is never too late to learn.

Sort Collections in Python

Tips

  1. You can use the built-in function sorted to sort any iterable collection. It always a (new) list containing sorted data. Some mutable collections (e.g., list) have thee method sort to sort elements in-place. Both sorted and Collection.sort accept an argument key for specifying customized sorting criteria.

Sort a List