human
Sort a binary array using one traversal | A Python program to sort a binary array.
if number is smaller than 1 then swap it with j - th number.
Driver program"
How can the above be solved in Python?
 ... Can you provide a code to sort a binary array using one traversal and the other steps required?
assistant
#Here is code to sort a binary array using one traversal and the other steps required.
 def sortBinaryArray ( a , n ) :
	j = - 1
	for i in range ( n ) :
		if a [ i ] < 1 :
			j = j + 1
			a [ i ] , a [ j ] = a [ j ] , a [ i ]
a = [ 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 ]
n = len ( a )
sortBinaryArray ( a , n )
for i in range ( n ) :
	print ( a [ i ] , end = " ▁ " )