MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / quick_sort

Function quick_sort

sorts/recursive_quick_sort.py:1–16  ·  view source on GitHub ↗

>>> for data in ([2, 1, 0], [2.2, 1.1, 0], "quick_sort"): ... quick_sort(data) == sorted(data) True True True

(data: list)

Source from the content-addressed store, hash-verified

1def quick_sort(data: list) -> list:
2 """
3 >>> for data in ([2, 1, 0], [2.2, 1.1, 0], "quick_sort"):
4 ... quick_sort(data) == sorted(data)
5 True
6 True
7 True
8 """
9 if len(data) <= 1:
10 return data
11 else:
12 return [
13 *quick_sort([e for e in data[1:] if e <= data[0]]),
14 data[0],
15 *quick_sort([e for e in data[1:] if e > data[0]]),
16 ]
17
18
19if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected