def quick_sort(collection):
 total_elements = len(collection)
 if (total_elements <= 1):
  return collection
 less = []
 equal = []
 greater = []
 pivot = collection[0]
 equal.append(pivot)
 for i in range(1, total_elements):
  element = collection[i]
  if (element < pivot):
   less.append(element)
  elif (element == pivot):
   equal.append(element)
  else:
   greater.append(element)
 return ((quick_sort(less) + equal) + quick_sort(greater))

def quick_sort ( collection ) : total_elements = len ( collection ) if ( total_elements <= 1 ) : return collection less = [ ] equal = [ ] greater = [ ] pivot = collection [ 0 ] equal . append ( pivot ) for i in range ( 1 , total_elements ) : element = collection [ i ] if ( element < pivot ) : less . append ( element ) elif ( element == pivot ) : equal . append ( element ) else : greater . append ( element ) return ( ( quick_sort ( less ) + equal ) + quick_sort ( greater ) )
pure implementation of quick sort algorithm in python .