For instance I have this list:
A = [(1, 2.5), (2, 5.0), (3, 7.5), (4, 10.0)]
and I have another list with the following entry:
B = [2.5, 7.5, 12.5]
What I want is a program in Python where if the 2nd element of each tuple in A, namely 2.5, 5.0, 7.5, and 10.0, can be found in B, it will create another variable which looks like this:
C = [(1, 2.5), (3, 7.5)]
where it removes the other tuples in A whose 2nd elements are not in B. I tried to code it this way:
A = [(1, 2.5), (2, 5.0), (3, 7.5), (4, 10.0)]
D = np.asarray(list(A))
E = []
if D[:, 1] in B:
E = np.append(E,D)
else:
pass
but I got an error of:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
7,5inBa typo for7.5?if D[:,1] in B: