0

So i made a translator that takes an English sentence, moves the last letter to the front, adds mu after each word and then adds emu after every three words. Now I would like to do the opposite. I cant seem to get past the part of now moving the first letter of the word to the end of the word. I was under the impression from this stack overflow post How to move the first letter of a word to the end that by using word[1:] + word[0] I could accomplish this, but I tried to implement this and it didn't seem to do anything.

Here is my current code:

sentence = 'imu odmu tnomu emu wknomu whomu otmu emu odmu sthimu'
#This is the result of the english translated sentence

#Get rid of mu and emu 
sentence = sentence.replace('mu', '')
sentence = sentence.replace('e ', '')

#I would like this to move the first letter of each word to the end
print("".join([words[1:] + words[0] for words in sentence]))

#Current output i od tno wkno who ot od sthi
#Expected Output i do not know how to do this

Just curious if someone can help explain to me what I'm missing here

Arxci
  • 95
  • 1
  • 7

1 Answers1

2

split() will take any string and split it into a list on whatever character you use in the call. The default is a space, so all you need to do is split the sentence into words, rather than operate on the characters.

sentence = 'imu odmu tnomu emu wknomu whomu otmu emu odmu sthimu'
#This is the result of the english translated sentence

#Get rid of mu and emu 
sentence = sentence.replace('mu', '')
sentence = sentence.replace('e ', '')

#I would like this to move the first letter of each word to the end
print(" ".join([words[1:] + words[0] for words in sentence.split()]))
>>> i do not know how to do this
Cole Robertson
  • 599
  • 1
  • 7
  • 18