1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
a = ((1, 2), 3, (4, 5)) foo = 4 found = True stack = list(a) while len(stack): elem = stack.pop(0) print 'Trying %s', elem if isinstance(elem, tuple): stack.extend(elem) else: if elem == foo: break else: found = False print found