0

How to do this ?take first letter of each word and put it on the end in python.

In python

21st Oct 2020, 11:05 AM
Divya Patil
Divya Patil - avatar
5 Réponses
- 1
This would work for a sentence. sentence = input().split() for words in sentence: newSentence = words[1:]+words[0] print(newSentence,end=" ") Edit: code modified.
21st Oct 2020, 11:13 AM
Avinesh
Avinesh - avatar
+ 2
string = string[1:] + string[0]
21st Oct 2020, 11:07 AM
QTWizard
+ 2
suppose the word is, a= "hello" since string is an array of characters you can use indexing and slicing to do something like this => newWord=a[1:]+a[0]
21st Oct 2020, 11:08 AM
Abhay
Abhay - avatar
+ 1
Avinesh split() will return a list, you're not required to convert it into a list again.
21st Oct 2020, 11:25 AM
QTWizard
+ 1
QTWizard my bad, thanks for the correction.
21st Oct 2020, 11:26 AM
Avinesh
Avinesh - avatar