2

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.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

3 Answers3

2

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?

NKR
  • 167
  • 9
1

This will do:

x = 'Muh    kay'   
x = ' '.join(i.capitalize() for i in x.split())
Prayson W. Daniel
  • 14,191
  • 4
  • 51
  • 57
0

I would do:

x.replace('\t', ' ')

However, this won't add the capital letter as the example shows.

J Agustin Barrachina
  • 3,501
  • 1
  • 32
  • 52