defQuickSort(a, left, right): if left>=right: return p = left + random.randrange(right-left+1) temp = a[left] a[left] = a[p] a[p] = temp i = left j = right x = a[i] while (i<j) : while (i<j) and (a[j]>x): # From big to small # while (i<j) and (a[j]<x): j = j - 1 a[i] = a[j] while (i<j) and (a[i]<=x): # From big to small # while (i<j) and (a[i]>=x): i = i + 1 a[j] = a[i] a[i] = x QuickSort(a, left, i-1) QuickSort(a, i+1, right)
n = int(input("The number of the list: ")) line = input("The unsorted list: ") a = list(map(int, line.split())) QuickSort(a, 0, n-1) for i in range(n): print(a[i], end=' ')
Notes
Keyboards input
To convert str to speical foramt list, using split() to seperate list and convert items’ type
Outputs format
To print a list in one line seperated by SPACE, using end=’ ‘, which can be used with other symbols like ‘,’