Reputation:
How can I get rid of that tab with regular expressions? I also need to do it on the fly because the name will be inside a list.
import re
x = 'Muh kay'
I want x to be
x = 'Muh Kay'
with only one space between them.
Upvotes: 2
Views: 844
Reputation: 4090
I would do:
x.replace('\t', ' ')
However, this won't add the capital letter as the example shows.
Upvotes: 0
Reputation: 15568
This will do:
x = 'Muh kay'
x = ' '.join(i.capitalize() for i in x.split())
Upvotes: 1
Reputation: 186
You can use something like this re.sub(r'\t', ' ', s) which will replace tabs with space. Please refer this answer: How to replace custom tabs with spaces in a string, depend on the size of the tab?
Upvotes: 2