我需要查看列表中的 2 个项目是否出现在另一个列表中,如果出现,请按它们在另一个列表中的位置比较这些项目。伪代码示例:
j=0
for x in mylist #loop through the list
i=0
for y in mylist #loop through the list again to compare items
if index of mylist[j] > index of mylist[i] in list1 and list2:
score[i][j] = 1 #writes the score to a 2d array(numpy) called score
i=i+1
else:
score[i][j]=0
i=i+1
j=j+1
示例叙述描述:
Names = [John, James, Barry, Greg, Jenny]
Results1 = [James, Barry, Jenny, Greg, John]
Results2 = [Barry, Jenny, Greg, James, John]
loop through Names for i
loop through Names for j
if (index value for john) > (index value for james) in results1 and
(index value for john) > (index value for james) results2:
score[i][j] = 1
有人可以指出我正确的方向吗?我一直在查看大量列表、数组和 .index 教程,但似乎没有任何内容可以回答我的问题