We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent abd9d78 commit 66433a5Copy full SHA for 66433a5
sorts/quick_sort.py
@@ -35,21 +35,20 @@ def quick_sort(collection):
35
>>> quick_sort([-2, -5, -45])
36
[-45, -5, -2]
37
"""
38
+ if len(collection) <= 1:
39
+ return collection
40
less = []
41
equal = []
42
greater = []
- if len(collection) > 1:
- pivot = collection[0]
43
- for x in collection:
44
- if x < pivot:
45
- less.append(x)
46
- if x == pivot:
47
- equal.append(x)
48
- if x > pivot:
49
- greater.append(x)
50
- return quick_sort(less) + equal + quick_sort(greater)
51
- else:
52
- return collection
+ pivot = collection[0]
+ for x in collection:
+ if x < pivot:
+ less.append(x)
+ elif x == pivot:
+ equal.append(x)
+ else:
+ greater.append(x)
+ return quick_sort(less) + equal + quick_sort(greater)
53
54
55
if __name__ == '__main__':
0 commit comments