I have a problem in which I have an array containing the letters in the alphabet. I was wondering what the best way to move the array elements a certain amount would be. For example, if the key is 2,
and
array = "A,B,C,D,E.."
how can I make is so that after the transformation,
array = "C,D,E,F,G..."
Would the simplest solution be an if statement?
Thanks
This should do it:
As you can see, you need a
forloop. Anifwon’t do it. It will shift allchars two to the left.The result will be:
['C', 'D', ..., 'Z', 'A', 'B']This method is called a circular shift.