+ 3

How can i add space (tab) to the pattern to make the words of the sentence not attached to each other

https://code.sololearn.com/cVFwL238bWUw/?ref=app

7th Sep 2022, 9:52 AM
Abdullah Essa
10 Respuestas
+ 4
Same way, you Add a space in pattern: pattern=r"[A-Za-z0-9 ]" #space included and end=""
7th Sep 2022, 11:17 AM
Jayakrishna 🇮🇳
+ 7
Abdullah Essa , the issue: the pattern that your code is using matches each character as a single match, but should be matched as words. the match looks like: ['l', 'e', 't', 's', 'g', 'o', 'a', 'n', 'd', 'g', 'e', 't', 'l', 'u', 'n', 'c', 'h'] > if you are not forced to use regex, a for loop or a list comprehension would be a good idea > if you wanted to stick with regex, the use of re.sub(...) is easy to understand. we can define the characters that should be removed, and replace them with an empty string. here is a link to the python docs regex: https://docs.python.org/3/library/re.html
7th Sep 2022, 11:15 AM
Lothar
Lothar - avatar
+ 4
thanks Jayakrishna🇮🇳 that was what i searching for
7th Sep 2022, 11:26 AM
Abdullah Essa
+ 4
Thank you for help my dear Lothar
7th Sep 2022, 11:26 AM
Abdullah Essa
+ 3
end='\t'
7th Sep 2022, 9:56 AM
Slick
Slick - avatar
+ 3
Thank you my friend Slick
7th Sep 2022, 11:27 AM
Abdullah Essa
+ 3
Abdullah Essa , just an other comment from me: the code is calling: re.findall (pattern,A) twice. this not required. try this: import re A=input() pattern=r"[A-Za-z0-9 ]" for i in re.findall (pattern,A): print(i , end="") # for better readability it is not recommended to combine 2 lines of code to one line.
7th Sep 2022, 4:47 PM
Lothar
Lothar - avatar
+ 2
But it makes space between every character. We need to select just the space in the input like we did here [A-Za-z0-9] Slick
7th Sep 2022, 10:08 AM
Abdullah Essa
+ 2
That's right brother Lothar l have changed the code 👍👍👍
7th Sep 2022, 6:59 PM
Abdullah Essa
+ 2
Try this pattern=r"[A-Za-z ]"
8th Sep 2022, 5:40 PM
Avinash
Avinash - avatar