0

私が作成したプログラムは、リストを出力します:

['2    19   2839475239874 hda'] 

次のようになります。

['2','19','2839475239874','hda']

したがって、4 つの部分からなるリストを作成する代わりに、1 つの大きな部分を作成します。リストを 4 つの部分に分けるにはどうすればよいですか?

ありがとう!私はしばらくこれに取り組んできましたが、実際に機能する答えは見つかりませんでした。

4

2 に答える 2

3
['2 19 2839475239874 hda'][0].split()
于 2013-07-11T15:00:15.403 に答える
2

str.split文字列を空白で分割するために使用します。

>>> lis = ['2 19 2839475239874 hda']
>>> lis[0].split()
['2', '19', '2839475239874', 'hda']

ヘルプstr.split:

>>> print (str.split.__doc__)
S.split(sep=None, maxsplit=-1) -> list of strings

Return a list of the words in S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
于 2013-07-11T15:00:10.467 に答える