mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 01:00:15 +00:00
64543faa98
* Make some ruff fixes * Undo manual fix * Undo manual fix * Updates from ruff=0.0.251
23 lines
485 B
Python
23 lines
485 B
Python
def quick_sort(data: list) -> list:
|
|
"""
|
|
>>> for data in ([2, 1, 0], [2.2, 1.1, 0], "quick_sort"):
|
|
... quick_sort(data) == sorted(data)
|
|
True
|
|
True
|
|
True
|
|
"""
|
|
if len(data) <= 1:
|
|
return data
|
|
else:
|
|
return [
|
|
*quick_sort([e for e in data[1:] if e <= data[0]]),
|
|
data[0],
|
|
*quick_sort([e for e in data[1:] if e > data[0]]),
|
|
]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import doctest
|
|
|
|
doctest.testmod()
|