variable in function should be lowercase (#768)

This commit is contained in:
sakuralethe 2019-04-26 17:43:51 +08:00 committed by John Law
parent 2fc2ae3f32
commit 48553da785

View File

@ -12,7 +12,7 @@ python quick_sort.py
from __future__ import print_function from __future__ import print_function
def quick_sort(ARRAY): def quick_sort(collection):
"""Pure implementation of quick sort algorithm in Python """Pure implementation of quick sort algorithm in Python
:param collection: some mutable ordered collection with heterogeneous :param collection: some mutable ordered collection with heterogeneous
@ -29,14 +29,14 @@ def quick_sort(ARRAY):
>>> quick_sort([-2, -5, -45]) >>> quick_sort([-2, -5, -45])
[-45, -5, -2] [-45, -5, -2]
""" """
ARRAY_LENGTH = len(ARRAY) length = len(collection)
if( ARRAY_LENGTH <= 1): if length <= 1:
return ARRAY return collection
else: else:
PIVOT = ARRAY[0] pivot = collection[0]
GREATER = [ element for element in ARRAY[1:] if element > PIVOT ] greater = [element for element in collection[1:] if element > pivot]
LESSER = [ element for element in ARRAY[1:] if element <= PIVOT ] lesser = [element for element in collection[1:] if element <= pivot]
return quick_sort(LESSER) + [PIVOT] + quick_sort(GREATER) return quick_sort(lesser) + [pivot] + quick_sort(greater)
if __name__ == '__main__': if __name__ == '__main__':