如何用python replace字符串中间多余的空格转换为一个空格

如题所述

# 不推荐
while '  ' in the_str:
    the_str = the_str.replace('  ', ' ')
    
其实可以用正则。

温馨提示:答案为网友推荐,仅供参考
相似回答