gpt4 book ai didi

python - 提取字符串 split() 操作产生的单个项目

转载 作者:行者123 更新时间:2023-12-01 06:15:02 24 4
gpt4 key购买 nike

a = line.splitlines()[:2]

我得到的输出如下所示。

['GET /en/html/dummy.php?name=MyName&married=not+single &male=yes HTTP/1.1']
['Host: www.explainth.at']
['User-Agent: Mozilla/5.0 (Windows;en-GB; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11']
['Accept: text/xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5']
['Accept-Language: en-gb,en;q=0.5']
['Accept-Encoding: gzip,deflate']
['Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7']
['Keep-Alive: 300']

我想获得前两项:

GET /en/html/dummy.php?name=MyName&married=not+single &male=yes HTTP/1.1
Host: www.explainth.at

最佳答案

获得前 2 件元素。

a[:2]

关于python - 提取字符串 split() 操作产生的单个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3699438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com