For example, I have a lst = "ABCXYZ"
, and I expect the output to be "CDEZAB"
The best method I've come up with so far is:
"".join(chr((ord(x)-ord('A')+2)%26+ord('A')) for x in lst)
Which is awkward. Using a dictionary like {'A': 'C', 'B': 'D', ……, 'X': 'Z', 'Y': 'A', 'Z': 'B'}
seems more Pythonic, but is even more awkward.
Any ideas?