if \'string1\' in line: ...
... works as expected but what if I need to check multiple strings like so:
if \'string1\' or \'string2
Using map
and lambda
a = ["a", "b", "c"]
b = ["a", "d", "e"]
c = ["1", "2", "3"]
# any element in `a` is a element of `b` ?
any(map(lambda x:x in b, a))
>>> True
# any element in `a` is a element of `c` ?
any(map(lambda x:x in c, a)) # any element in `a` is a element of `c` ?
>>> False
and high-order function
has_any = lambda b: lambda a: any(map(lambda x:x in b, a))
# using ...
f1 = has_any( [1,2,3,] )
f1( [3,4,5,] )
>>> True
f1( [6,7,8,] )
>>> False