Settings

Theme

How to Sort a List in Python

ao.gl

3 points by aogl 5 years ago · 3 comments

Reader

dalke 5 years ago

Python has a sorting HOWTO at https://docs.python.org/3/howto/sorting.html . I was the original author, back in around 1998 or so. This new article covers a subset of that HOWTO.

babu_bhaiya 5 years ago

What is the time complexity? O(n log n) most probably. And what actual sort does it use? Quick sort or merge sort or any other?

  • dalke 5 years ago

    https://en.wikipedia.org/wiki/Timsort

    > In the worst case, Timsort takes O(n logn) comparisons to sort an array of n elements. In the best case, which occurs when the input is already sorted, it runs in linear time, meaning that it is an adaptive sorting algorithm.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection