<分区> 分区>
例如,在 python 中,我有以下字符串:
a = "Sentence with weird whitespaces"
我想用一个扩展空格替换同一个字符串,所以最后的字符串会是这样
'Sentence with weird whitespaces'
我自己找到了解决方案,但是有更好/更短的解决方案吗?
' '.join([x for x in a.split(' ') if len(x)>0])
<分区> 分区>
例如,在 python 中,我有以下字符串:
a = "Sentence with weird whitespaces"
我想用一个扩展空格替换同一个字符串,所以最后的字符串会是这样
'Sentence with weird whitespaces'
我自己找到了解决方案,但是有更好/更短的解决方案吗?
' '.join([x for x in a.split(' ') if len(x)>0])