File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed
Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -35,21 +35,20 @@ def quick_sort(collection):
3535 >>> quick_sort([-2, -5, -45])
3636 [-45, -5, -2]
3737 """
38+ if len (collection ) <= 1 :
39+ return collection
3840 less = []
3941 equal = []
4042 greater = []
41- if len (collection ) > 1 :
42- 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
43+ pivot = collection [0 ]
44+ for x in collection :
45+ if x < pivot :
46+ less .append (x )
47+ elif x == pivot :
48+ equal .append (x )
49+ else :
50+ greater .append (x )
51+ return quick_sort (less ) + equal + quick_sort (greater )
5352
5453
5554if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments