Swap first N characters with last N characters
for j in range ( N ) : NEW_LINE INDENT temp = S [ j ] NEW_LINE S [ j ] = S [ j + N ] NEW_LINE S [ j + N ] = temp NEW_LINE DEDENT S = ' ' . join ( S ) NEW_LINE