For example,
a = 'My\t\t\tname\t\tis...'
should become
'My name is...' Use the replace () method, which will replace all tabs with spaces:
a = a.replace("\t", " ") You can read more about this method here .
And the same can be done with regular expressions:
import re s = "The \t fox jumped \t over \t the log." s = re.sub("\s+", " ", s) print s a = a.replace("\t", " ") - 3 spaces in a row will work - slippykVery simple and, IMHO, elegant solution:
' '.join(a.split()) x = 'My\t\t\tname\t\tis...'.split('\t') ' '.join([i for i in x if i != '']) ' '.join(filter(bool, a.split('\t'))) Source: https://ru.stackoverflow.com/questions/601572/
All Articles