+ 3
How can i add space (tab) to the pattern to make the words of the sentence not attached to each other
10 Respuestas
+ 4
Same way, you Add a space in pattern:
pattern=r"[A-Za-z0-9 ]" #space included
and end=""
+ 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
+ 4
thanks Jayakrishna🇮🇳 that was what i searching for
+ 4
Thank you for help my dear Lothar
+ 3
end='\t'
+ 3
Thank you my friend Slick
+ 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.
+ 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
+ 2
That's right brother Lothar l have changed the code 👍👍👍
+ 2
Try this pattern=r"[A-Za-z ]"