text - How do I replace a word in a string in python? -


let have string

c = "a string , roberta a thanks" 

i want output as

' string , roberta   thanks" 

this trying

c.replace('a', ' ')  ' string  nd robert       thnks' 

but replaces each 'a' in string

so tried

c.replace(' ', ' ')   'a string , roberta      thanks' 

but leaves out 'a' in starting of string.

how do this?

this looks job re :

import re while re.subn('(\s+a\s+|^a\s+)',' ',txt)[1]!=0:     txt=re.subn('(\s+a\s+|^a\s+)',' ',txt)[0] 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -