I have tried the following ways based on the answers obtained here in the forum.
First form:
A = [[1,2,3,4,5,6,7,8,9,10],[1,3,5,7,8,9,10,20],[4,5,7,13,16,20,21,30]]
B = [1,2,3,4,5,6,7,8,9]
C = [10,11,12,13,14,15,16,17,18,19]
D = [20,21,22,23,24,25,26,27,28,29,30]
def contagem_interseccao(a,b,c,d):
s = set(a)
return len(s.intersection(b,c,d))
print(contagem_interseccao(A,B,C,D))
Second form:
A = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10),(1,3,5,7,8,9,10,20),(4,5,7,13,16,20,21)
B = 1, 2, 3, 4,5,6,7,8,9
C= 10,11,12,13,14,15,16,17,18,19
D= 20,21,22,23,24,25
def contagem_interseccao(a, b,c,d):
s = set(a)
return len(s.intersection(b,c,d))
print(contagem_interseccao(A, B,C,D))
Third way:
A = [[1,2,3,4,5,6,7,8,9,10],[1,3,5,7,8,9,10,20],[4,5,7,13,16,20,21,30]]
B = [1,2,3,4,5,6,7,8,9]
C = [10,11,12,13,14,15,16,17,18,19]
D = [20,21,22,23,24,25,26,27,28,29,30]
n = len(set(A) & set(B))
l = len(set(A) & set(C))
k = len(set(A) & set(D))
print(list(n,l,k))
I expected the following answer:
[9 1 0, 6 1 1, 3 2 3]
In 2 cases the error is always the same: TYPE ERROR: UNHASHABLE TYPE: "LIST"
And in 1 case the result is 0.
Is this use of the set wrong? Am I on the right path? Could someone give me a light? Thankful.