1def swap(A, i, j):
2
3 temp = A[i]
4 A[i] = A[j]
5 A[j] = temp
6
7
8# Function to move all zeros present in a list to the end
9def partition(A):
10
11 j = 0
12
13 # each time we encounter a non-zero, `j` is incremented, and
14 # the element is placed before the pivot
15 for i in range(len(A)):
16 if A[i]: # pivot is 0
17 swap(A, i, j)
18 j = j + 1