I want to swap each pair of characters in a string. \'2143\' becomes \'1234\', \'badcfe\' becomes \'abcdef\'.
\'2143\'
\'1234\'
\'badcfe\'
\'abcdef\'
How
There is no need to make a list. The following works for even-length strings:
r = '' for in in range(0, len(s), 2) : r += s[i + 1] + s[i] s = r