human
Generate lexicographically smallest string of 0 , 1 and 2 with adjacent swaps allowed | Function to print the required string.
count number of 1 s.
To check if the all the 1 s have been used or not.
Print all the 1 s if any 2 is encountered.
If Str1 [ i ] = 0 or Str1 [ i ] = 2.
If 1 s are not printed yet.
Driver code"
How can the above be solved in Python?

What is a code to generate lexicographically smallest string of 0 , 1 and 2 with adjacent swaps allowed and the other steps required?
assistant
#Here is code to generate lexicographically smallest string of 0 , 1 and 2 with adjacent swaps allowed and the other steps required.
 def printString ( Str1 , n ) :
	ones = 0
	for i in range ( n ) :
		if ( Str1 [ i ] == '1' ) :
			ones += 1
	used = False
	for i in range ( n ) :
		if ( Str1 [ i ] == '2' and used == False ) :
			used = 1
			for j in range ( ones ) :
				print ( "1" , end = " " )
		if ( Str1 [ i ] != '1' ) :
			print ( Str1 [ i ] , end = " " )
	if ( used == False ) :
		for j in range ( ones ) :
			print ( "1" , end = " " )
Str1 = "100210"
n = len ( Str1 )
printString ( Str1 , n )