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

2
  • 3
    for words in sentence does not produce words; it produces individual characters. If you want words, use for words in sentence.split() Commented Feb 7, 2020 at 20:12
  • Yeah silly me forgot to split it before hand Commented Feb 7, 2020 at 20:15

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Since my answer works, I'd appreciate it you accepted it:)
Yeah, I just have to wait a few more mins

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.