The problem is a known one: Given a sentence, return the sentence with all its letters transposed by 1 in the alphabet, but only if the letter is a-y.
I understand similar questions have been asked here bunch of times, but the solution I applied in my case actually came from one of these stackoverflow answers and the function still keeps jumping 2-3 letters ahead:
from string import ascii_letters
def inverter(sentence):
for x in sentence:
if x in ascii_letters and x!= 'z' and x != ' ':
sentence = sentence.replace(x,ascii_letters[ascii_letters.index(x)+1])
else:
sentence = sentence
return sentence
sent3 = 'a quick brown fox jumps over the lazy dog'
inverter(sent3)
Output:
'c uwkem cuqzq hqz kwnqu qwfu uif mczz eqh'
What could be going wrong in the loop of mutation?