基于索引的Python列表操作

2024-05-19 08:11:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两张单子:

第一个列表包括各种出版物的所有标题,第二个列表包括所有作者姓名。你知道吗

list B = ['Moe Terry M 2005 ', 'March James G and Johan P Olsen 2006 ', 'Kitschelt Herbert 2000 ', 'Bates Robert H 1981 ' , .......]

list A = ['"Linkages between Citizens and Politicians in Democratic Polities,"', '"Winners Take All: The Politics of Partial Reform in Postcommunist \n\nTransitions,"', '"Inequality, Social Insurance, and \n\nRedistribution."', '"Majoritarian Electoral Systems and \nConsumer Power: Price-Level Evidence from the OECD Countries."']

我在跑步学者.py作为bash命令。语法是这样的

scholar = "python scholar.py -c 1 --author " + str(name) + "--phrase  " + str(title) 

现在,我要做的是把每一个书名和作者都整理好,这样我就可以和书生一起使用它们了。 但我不知道如何才能得到第一作者的名字和第一个标题。你知道吗

如果列表很小,我会使用索引。你知道吗


Tags: andinpy标题列表作者出版物list
1条回答
网友
1楼 · 发布于 2024-05-19 08:11:36

这就是你要找的吗?你知道吗

list B = ['Moe Terry M 2005 ', 'March James G and Johan P Olsen 2006 ', 'Kitschelt Herbert 2000 ', 'Bates Robert H 1981 ' , .......]

list A = ['"Linkages between Citizens and Politicians in Democratic Polities,"', '"Winners Take All: The Politics of Partial Reform in Postcommunist \n\nTransitions,"', '"Inequality, Social Insurance, and \n\nRedistribution."', '"Majoritarian Electoral Systems and \nConsumer Power: Price-Level Evidence from the OECD Countries."']

for i,j in zip(B,A):
     print i, j #python 2.x
     print(i , j) #python3.x

相关问题 更多 >

    热门问题