- 1

[SOLVED] If we have given a string as a input and there is space between words.can we separate the words and print?

9th Feb 2020, 11:04 AM
Varsha
Varsha - avatar
10 Respostas
+ 6
string = "hello Dharani" string = string.split() print(string) >>>["hello", "Dharani"] ..string is now splitted into words separrated by comma
9th Feb 2020, 11:11 AM
r8w9
r8w9 - avatar
+ 2
Jayakrishna for word in words: print(word)
9th Feb 2020, 11:57 AM
Oma Falk
Oma Falk - avatar
+ 1
In what language..? Pls Tag specific language... It can done by Predefined functions for splitting words by a separator space.. For ex: in java String s[] =in.nextLine(). split(" "); s[] array stores input line separated by space into words.. 'in' is the Scanner object... Ex: input hello World and hi s[0]= hello s[1]=World S[2]=and S[3]=hi
9th Feb 2020, 11:12 AM
Jayakrishna 🇼🇳
+ 1
You need to give us more details. What language is this about? And what exactly want to do with the words? (Just for output, you don't need to split.)
9th Feb 2020, 11:16 AM
HonFu
HonFu - avatar
+ 1
Oma Falk yes.. Thank you.. Is that prints in reverse order.. I don't know much about python.. But guessing may be print in order only... @Dharani asked it in reversing print..
9th Feb 2020, 12:02 PM
Jayakrishna 🇼🇳
+ 1
Thank you for your replies
9th Feb 2020, 12:10 PM
Varsha
Varsha - avatar
0
I have to slice the string and combine .is it possible?
9th Feb 2020, 11:13 AM
Varsha
Varsha - avatar
0
If I give input string as "hello dharani" the output will print like "dharani hello" .I want to write it in python
9th Feb 2020, 11:15 AM
Varsha
Varsha - avatar
0
words = "hello dharani" words = words.split(" ") counter = len(words) -1 min_index = 0 for i in range(len(words)-1,-1,-1) : print(words[i],end=" ") I tried... But It may be simplified... Edit: from below suggestions.. words = "hello dharani" words = words.split(" ") for word in reversed(words): print(word, end=" ") @Dharani Wel come. Hope it helped you..
9th Feb 2020, 11:48 AM
Jayakrishna 🇼🇳
0
for word in reversed(words): ...
9th Feb 2020, 12:04 PM
HonFu
HonFu - avatar