How can I find the space between words in a text? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I find the space between words in a text?

9th May 2020, 8:33 PM
Fatemeh Ghafouri
8 Answers
+ 3
Returns a list with index number of spaces in a text def space(text): j=0 l=[] for i in text: if i==" ": l.append(j) j+=1 return l
9th May 2020, 9:19 PM
Abhay
Abhay - avatar
+ 1
I didn't knew there was isspace also lol! i would just do For i in text: If i!=" ": print(i)
9th May 2020, 8:44 PM
Abhay
Abhay - avatar
10th May 2020, 10:35 AM
narayanaprasad
narayanaprasad - avatar
+ 1
def nospaces(x): print(''.join(i for i in x if i != chr(32)))
10th May 2020, 11:25 AM
madeline
madeline - avatar
0
I want to define a function for it
9th May 2020, 8:38 PM
Fatemeh Ghafouri
0
I don't want to use pre-written commands
9th May 2020, 8:40 PM
Fatemeh Ghafouri
0
Are you trying to return the count of spaces in a string/text?
9th May 2020, 8:45 PM
rodwynnejones
rodwynnejones - avatar
0
rodwynnejones In fact, I want to write a command to return the words of a text without using the split command, so I want to first define a function to find the space between the words.
9th May 2020, 9:04 PM
Fatemeh Ghafouri