您可以使用.replace('\t',' ')
或.expandtabs()
然后输入的所有新制表符将更改为空格。
尝试这个
def break_words(stuff):
words = stuff.replace('\t','').split(' ')
return sorted(words)
sentence = 'All god'+"\t"+'things come to those who weight.'
print sentence#works as expected
words = break_words(sentence)
print w
输出:
All god things come to those who weight.
['All', 'come', 'godthings', 'those', 'to', 'weight.', 'who']
或这个
def break_words(stuff):
words = stuff.replace('\t',' ').split(' ')
return sorted(words)
sentence = 'All god'+"\t"+'things come to those who weight.'
print sentence#works as expected
words = break_words(sentence)
print words
输出:
All god things come to those who weight.
['All', 'come', 'god', 'things', 'those', 'to', 'weight.', 'who']
此致 :)