Can't find any similar questions online, would appreciate the help. I would like to find out if two values appear in any lists. For example, I have
A = [1, 3, 5, 4]
B = [5, 7, 9, 0]
C = [2, 7, 3, 9]
Are there any quick methods to check if [1, 2]
is present anywhere in order in the lists?
CodePudding user response:
Something like
any([(1, 2) in zip(lst, lst[1:]) for lst in [A, B, C]])
CodePudding user response:
Python offers an easy way to check if an element is part of a list:
A = [1, 3, 5, 4]
B = [5, 7, 9, 0]
C = [2, 7, 3, 9]
values = [1, 2]
for v in values:
if (v in A):
print("A has {}".format(v))
if (v in B):
print("B has {}".format(v))
if (v in C):
print("C has {}".format(v))