+ 1
replace a character python
sentence = ' mam a a mam ' sentence = re.sub(' a ', ' ', sentence) print(sentence) output: mam a mam expected output: mam mam is there a short and simple solution to this problem??
4 odpowiedzi
+ 1
Calvin [Inactive] thanks but is there a way to use metacharactors to do this??
0
re.sub() matches all occurences of the pattern if no count parameter has been set.
So pay attention to the blanks in your pattern and replacement strings.
They should be " a" and an empty string, just two quotes without anything in between : ''.
I deleted some blanks, tried your code and got the expected output.
0
Delorme can u please share the program??
0
Kairav Bhatia Here you are ; I just changed
' a ' to ' a' and ' ' to '' :
https://code.sololearn.com/c6S1L4Wm1b91/?ref=app