Example input = [ 0 , 1 , 2 , 2 , 0 , 0 ] output = [ 0 , 0 , 0 , 1 , 2 , 2 ]
inputArray = [ 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 ] NEW_LINE outputArray = [ ] NEW_LINE indexOfOne = 0 NEW_LINE for item in inputArray : NEW_LINE INDENT if item == 2 : NEW_LINE INDENT outputArray . append ( item ) NEW_LINE DEDENT elif item == 1 : NEW_LINE INDENT outputArray . insert ( indexOfOne , item ) NEW_LINE indexOfOne += 1 NEW_LINE DEDENT elif item == 0 : NEW_LINE INDENT outputArray . insert ( 0 , item ) NEW_LINE indexOfOne += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( " ▁ wrong ▁ value ▁ - ▁ Aborting ▁ " ) NEW_LINE continue NEW_LINE DEDENT DEDENT print ( outputArray ) NEW_LINE