There are many ways to do this. The most direct translation is:
any_in = lambda a, b: any(i in b for i in a)
You could also use various things involving sets, such as:
any_in = lambda a, b: bool(set(a).intersection(b))
(which depends on the elements of a
being hashable, but if that's true, it'll probably be faster to make a set of the larger out of a
and b
for either of these approaches).
Edit: isdisjoint
is better than intersection
for Python 2.6 and above, as noted by various people below. Glad to learn about that. :)