简体   繁体   English

Python - 比较列表列表

[英]Python - Comparing list of lists

在此处输入图片说明

I have a list with 3 lists and 3 other lists with 3 lists inside.我有一个包含 3 个列表的列表和 3 个其他列表,其中包含 3 个列表。

I want to compare the first index of list A with the first indexes of the first list B ...我想将列表 A 的第一个索引与第一个列表 B 的第一个索引进行比较...

Comparing the 22 with the 2,6,3 ... the 3 with the 4,4,66比较 22 与 2,6,3 ... 3 与 4,4,66

Can help me ?可以帮我 ?

a = [[22,3,3], [5,3,7],[1,6,3]]

b = [[2,4,7], [6,4,8],[3,66,13]] , [[2,23,6], [5,13,7],[11,6,34]] , [[22,53,6], [54,3,7],[11,6,33]]

You can try this out:你可以试试这个:

a = [[22,3,3], [5,3,7],[1,6,3]]

b = [[2,4,7], [6,4,8],[3,66,13]] , [[2,23,6], [5,13,7],[11,6,34]] , [[22,53,6], [54,3,7],[11,6,33]]

for i in range(len(a)):
    for j in range(len(a[i])):
        for x in range(len(b)):
            for y in range(len(b[x])):
                for z in range(len(b[y])):
                    if (a[i][j]==b[x][y][z]):
                        print('true')
                    else:
                        print('false')

As it prints true or false it is going to give you a long output.当它打印 true 或 false 时,它​​会给你一个很长的输出。 You can modify it as per your needs, and it compares properly as you mentioned in your question.您可以根据自己的需要对其进行修改,并且如您在问题中提到的那样进行正确比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM