0

I have 2 lists with lot of sub-lists in it (approx 28000) like below:

list1 = [[1,0,0],[1,0,1],[1,1,0],[1,2,0],[2,0,1],[2,1,1]]
list2 = [[1,0,0],[1,0,1],[1,0,2],[1,1,0],[1,1,1],[1,2,0],[1,2,1],[2,0,1],[2,0,2],[2,1,1],[2,1,2],[3,0,1]]

Each sub-list would always have 3 values. Consider them as [x,y,z]

Now I want to get counts like below, when I do the comparison among list1 and list2:

Expected_Results_in_Excel

This count is calculated like for [1,0,0],[1,0,1],[1,1,0],[1,2,0]: x is 1, for x value how many y values(0,1,2) and how many z values(0,1) are there.

So for x=1, in list1, y=3 and z=2.

Count would be taken on y and z values.

Kindly let me know if anyone have any ways to do this.

Suman KK
  • 1
  • 2
  • Does this answer your question? [How do I count the occurrences of a list item?](https://stackoverflow.com/questions/2600191/how-do-i-count-the-occurrences-of-a-list-item) – Marcus Müller Oct 28 '22 at 12:15
  • but even without these tricks, this would really just take two nested for loops and a map. Not quite sure where you're stuck! – Marcus Müller Oct 28 '22 at 12:16

1 Answers1

0

I could not understand the relationship between the 2 lists, but I think that the better way you can do it is by using pattern matching.

You can make patterns and take an action per patter.

Example:

for sublist in listA:
    match sublist:
        case [_,1,1]:
            # do something
            ...
        case _:

it's awesome! Seach for it.