Avatar ·

将行中的双空格替换为单空格

📁 行, python, 工作

我有一行:

str = 'a l a m a k o t a '

如你所见,在这行中,同一个单词的字母之间有一个空格,单词之间有两个空格。

我尝试解决,但失败了:

我曾尝试将双空格改为'`':

for i in range(len(str)-1):
if str[i] == ' ' and str[i+1] == ' ':
comment.replace('str[i]', '')
comment.replace('str