def nested_contains(what, where): if what in where: return True for x in where: if isinstance(x, (list, tuple)): if nested_contains(what, x): return True return False