def quick_sort(list, start, end):

# If start smaller than end, continue sorting

if start < end:

left = start

right = end

# Set the first item as pivot

pivot = list[left]

# Do compare while pointer left smaller than right

# Move the smaller one to left part and bigger one to right part

while left < right:

#if the item of pointer right item bigger than move the pointer right back

while (left < right) and (list[right] >= pivot):

right -= 1

# Now, we find the a item smaller than pivot,so set list[left] = list[right]

if left < right:

list[left] = list[right]

left += 1

# Than we scan left part in than same way

while (left < right) and (list[left] <= pivot):

left += 1

# Now, we find the a item bigger than pivot,so set list[right] = list[left]

if left < right:

list[right] = list[left]

right -= 1

# After comparison, the list is separated to two parts,

# and pointer left and right are in the same place

# So we set pivot in this place

list[left] = pivot

print(list)

#递归前后半区

# Now recurse the quick_sort(）

# Left part is [start, left - 1]

# Right part is [right + 1, end]

quick_sort(list, start, left - 1)

quick_sort(list, right + 1, end)

return list

if __name__ == "__main__":

before = [5, 3, 4, 6, 12, 2, 8]

print("Result:")

after = quick_sort(before, 0, len(before)-1 )

print(after)