简体   繁体   中英

Python - Comparing list of lists

在此处输入图片说明

I have a list with 3 lists and 3 other lists with 3 lists inside.

I want to compare the first index of list A with the first indexes of the first list B ...

Comparing the 22 with the 2,6,3 ... the 3 with the 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. You can modify it as per your needs, and it compares properly as you mentioned in your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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