I have two lists of lists that will always have the same lengths.
l1 = [[0, 1, 2, 2, 0, 1, 2], [0, 1, 0, 0, 0], [0, 1, 2, 0, 0]]
l2 = [[0, (1, 'a', 'b'), (1, 'a', 'b'), (1, 'a', 'b'), 0, (3, 'x', 'y'), 0], [0, (2, 'c', 'd'), 0, 0, 0], [0, (3, 'e', 'f'), 0, 0, 0]]
What I want is to return the nonzero elements of l2 only if the quantity of identical elements much the sequence of` 1-2s from l1 (or just 1s). In this case for example, I would like it to return just
out = [[(1, 'a', 'b'), (1, 'a', 'b'), (1, 'a', 'b')], [(2, 'c', 'd')], []]
because there are three identical tuples and a sequence of 1, 2, 2, while for (3, 'e', 'f'), there is only on but there is a sequence of 1, 2 (so it should have been (3, 'e', 'f'), (3, 'e', 'f') instead in l2.
What I have been trying to do is use collections.Counter to count the occurrences of nonzero elements, but when counting 1 and 2s it does not differentiate between sequences, so I cannot do a comparison:
for x, y in zip(l1, l2):
print(Counter(x), Counter(y))
returns
Counter({2: 3, 0: 2, 1: 2}) Counter({0: 3, (1, 'a', 'b'): 3, (3, 'x', 'y'): 1})
Counter({0: 4, 1: 1}) Counter({0: 3, (2, 'c', 'd'): 2})
Counter({0: 5}) Counter({0: 4, (3, 'e', 'f'): 1})
There is no way to no what the count of 1 and 2 correspond to.
Any help on how to go about doing this?
Some input-expected output examples:
l1 = [[0, 1, 2, 0], [0, 1]]
l2 = [[0, (1, 'a', 'b'), (1, 'a', 'b'), 0], [(2, 'a', 'b'), (2, 'a', 'b')]]
out = [[(1, 'a', 'b'), (1, 'a', 'b')], []]
l1 = [[2, 2, 2], [1, 2]]
l2 = [[(1, 'a', 'b'), (1, 'a', 'b'), (1, 'a', 'b')], [(2, 'a', 'b'), (2, 'a', 'b')]]
out = [[(1, 'a', 'b'), (1, 'a', 'b'), (1, 'a', 'b')], [(2, 'a', 'b'), (2, 'a', 'b')]]
l1 = [[0, 1], [0, 0]]
l2 = [[0, (3, 'x', 'y')], [0, 0]]
out = [[(3, 'x', 'y')], []]