Python 除去文本中的所有空白,实际的单个空格除外

Python 除去文本中的所有空白,实际的单个空格除外,python,regex,Python,Regex,在python3中我将如何做到这一点 The quick brown fox jumps over the lazy dog. 到 其中,上面的引号是一个字符串。此处不需要使用regex。您可以通过以下方式实现您想要的: a = "The quick brown fox jumps over the lazy dog." final = " ".join(a.split(

在python3中我将如何做到这一点

The            quick     brown                fox jumps over the  lazy dog.


其中,上面的引号是一个字符串。

此处不需要使用
regex
。您可以通过以下方式实现您想要的:

a = "The            quick     brown                fox jumps over the  lazy dog."
final = " ".join(a.split())
print(final) 
输出:

'The quick brown fox jumps over the lazy dog.'
'The quick brown fox jumps over the lazy dog.'