使用python中的空格将一行拆分为三个部分

时间:2013-06-28 10:01:18

标签: python

我有一行文字,如下:

http://www.example.org/lexicon#13797906 http://www.monnetproject.eu/lemon#gloss an overwhelming number or amount; "a flood of requests"; "a torrent of abuse"

我想将它分成三部分,但只是使用前两个空格作为它们应该被分割的点。这是我正在寻找的结果:

http://www.example.org/lexicon#13797906 
http://www.monnetproject.eu/lemon#gloss 
an overwhelming number or amount; "a flood of requests"; "a torrent of abuse"

我曾教过maxsplit可以工作,但我不知道如何在这种情况下使用它

1 个答案:

答案 0 :(得分:5)

str.split方法采用可选计数:

text.split(' ', 2)
相关问题