In 13 cpaste Pasting code enter -- alone on the line to stop def neste

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
In [13]: %cpaste
Pasting code; enter '--' alone on the line to stop.
: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
:--
In [14]: where = ((1, 2), 3, (4, 5))
In [15]: nested_contains(3, where)
Out[15]: True
In [16]: nested_contains(4, where)
Out[16]: True
In [17]: nested_contains(9, where)
Out[17]: False