s = "WRWRWWRRR" print(s) print() for i in range(len(s)-1): for j in range(i+1,len(s)): if s[i] > s[j]: print("swap {} and {}".format(i,j)) s = s[:i] + s[j] + s[i+1:j] + s[i] + s[j+1:] print(s) print()
Standard input is empty
WRWRWWRRR swap 0 and 1 RWWRWWRRR swap 1 and 3 RRWWWWRRR swap 2 and 6 RRRWWWWRR swap 3 and 7 RRRRWWWWR swap 4 and 8 RRRRRWWWW