Find an index to swap and create second permutation
for j in range ( next_pos , n ) : NEW_LINE INDENT if ( arr [ j ] [ 0 ] == arr [ j - 1 ] [ 0 ] ) : NEW_LINE INDENT temp = arr [ j ] NEW_LINE arr [ j ] = arr [ j - 1 ] NEW_LINE arr [ j - 1 ] = temp NEW_LINE next_pos = j + 1 NEW_LINE break NEW_LINE DEDENT DEDENT