はどのように私は、この関数を定義するが、私はtest = reducing_white(test)
しようとすると、それがすべてでは動作しません試してみましたtest = ' Good '
Pythonの空白を減らすには?
単一の空白に
test = ' Good '
からPythonで空白を減らすやる、それが関連していません関数の戻り値か何か?ここで
counter = []
def reducing_white(txt):
counter = txt.count(' ')
while counter > 2:
txt = txt.replace(' ','',1)
counter = txt.count(' ')
return txt
重複したhttp://stackoverflow.com/questions/2077897/substitute-multiple-whitespace-with-single-whitespace-in-pythonまたはhttp://stackoverflow.com/questions/1546226/a-simple-way -to-multiple-spaces-in-a-string-in-python? – alecxe
ループの最初の繰り返しで 'return'を呼び出します。ループの外側に 'return'を置くつもりだったのでしょうか? – larsks
コードはあまり意味をなさない。一つは、連続したスペースと孤立したスペースを区別しないことです。 –