gpt4 book ai didi

python - python 的 sorted() 使用什么算法?

转载 作者:IT老高 更新时间:2023-10-28 20:27:08 26 4
gpt4 key购买 nike

Possible Duplicate:
About python's built in sort() method

名字说明一切。

我试图向某人解释为什么他们应该使用 Python 的内置 sorted() 函数而不是滚动他们自己的函数,但我意识到我不知道它使用什么算法。

如果重要的话,我们说的是 python 2.7

最佳答案

Python 使用一种称为 Timsort 的算法。 :

Timsort is a hybrid sorting algorithm, derived from merge sort and insertion sort, designed to perform well on many kinds of real-world data. It was invented by Tim Peters in 2002 for use in the Python programming language. The algorithm finds subsets of the data that are already ordered, and uses the subsets to sort the data more efficiently. This is done by merging an identified subset, called a run, with existing runs until certain criteria are fulfilled. Timsort has been Python's standard sorting algorithm since version 2.3. It is now also used to sort arrays in Java SE 7, and on the Android platform.

关于python - python 的 sorted() 使用什么算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10948920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com