Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the built-in function "sorted" work in Python? [duplicate]

x = [1, 4, 7, 65, 23, 57, 12]
>>> sorted(x)
[1, 4, 7, 12, 23, 57, 65]

Just out of curiosity, how does this function work? What is the algorithm that Python uses to sort iterables?

like image 561
user3114227 Avatar asked Dec 20 '25 19:12

user3114227


1 Answers

Python used to use Quicksort.

Then, the mighty Tim Peters came along, with a level 20 keyboard and coding chops that were over 9000; and in a magnificent symphony of elegance and brilliance, built Timsort and gifted it to us mere mortals, for our lives would be incomplete without it.

like image 174
inspectorG4dget Avatar answered Dec 22 '25 09:12

inspectorG4dget



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!