Given a list array a, and another list b and d. How can I check if list element in a exists in b (or another example, in d)? I know I can do it with a for loop of a element and check if each element is in b/d, but is there any API do it quickly?
a = [[1,4], [17,33,2],[2,33]]
b = [1,4,5,6]
c = [[1,4]]
d = [2,33]
e = [[17,33,2],[2,33]]
Let put it this way, give list a and b, how can I write the loop below efficiently? Let say in one line using list comprehension.
newls = []
for sublist in a:
newls.append(list(set(sublist).intersection(set(b))))
a, and test whether the intersection of the sublists with the given list is non-empty.cande, or do you just need to test?