2
I tried it in the following ways based on answers achieved 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 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]
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 set usage wrong? Am I on the right track? Could someone give me a light? Grateful.
Obg by Anderson class, I mean, answer, hahaha. I had not understood at first and I spent all these days (nights) trying to solve the problem. His reply helped me in two important steps of my project and it became much easier to analyze the data. I am new (2 months) in programming and the way you answered made me have to research and learn more from it and I thank you for that tbm. Well, that’s it man, obg once again and see you on the site, abç.
– Eduardo Marques