python sort complexity


As others have mentioned, the built-in sorting algorithm of Python uses a special version of merge sort, called Timsort, which runs in  nlog2n  time.

That’s pretty good; we generally can’t get much better than  nlog2n (with the exception of sorts which are slightly optimized for certain arrangements of data).

You can read more about how Timsort works (it’s pretty cool!) here:

Here is what the above code is Doing:
1. It’s creating a list of random numbers.
2. It’s sorting the list using the built-in sort function.
3. It’s printing the list to the screen.

The output of the code should look something like this:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]