mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
hyphen_files = [file for file in filepaths if "-" in file] (#2447)
* hyphen_files = [file for file in filepaths if "-" in file]
* updating DIRECTORY.md
* Rename recursive-quick-sort.py to recursive_quick_sort.py
* updating DIRECTORY.md
* Rename aho-corasick.py to aho_corasick.py
* updating DIRECTORY.md
* Rename polynom-for-points.py to polynom_for_points.py
* updating DIRECTORY.md
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
22
sorts/recursive_quick_sort.py
Normal file
22
sorts/recursive_quick_sort.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user