2012-02-09 11 views
4

私の文字列は次のとおりです。Pythonで空白を含まない単語に文字列を分割する方法は?

"This  is a  string" 

私はリストにそれを有効にする:

["This", "is", "a", "string"] 

私はsplit(" ")メソッドを使用しますが、それは、リストの要素として空白を追加します。あなただけ.split()を使用する場合、それはthe docs同様代わりに.split(' ')

>>> "This  is a  string".split() 
['This', 'is', 'a', 'string'] 
+1

split()を使用すると、 – WeaselFox

答えて

11
>>> v="This is a string" 

>>> v.split() 
['This', 'is', 'a', 'string'] 

だけsplit()を使用しています。

3

引数を渡さない、と言います。

>>> "This is a string".split() 
['This', 'is', 'a', 'string'] 
2

の、要素として空白を追加しません、助けてください

よろしく

関連する問題