Skip to content

Instantly share code, notes, and snippets.

@james-m
Created May 22, 2013 19:05
Show Gist options
  • Save james-m/5630053 to your computer and use it in GitHub Desktop.
Save james-m/5630053 to your computer and use it in GitHub Desktop.
DATA = [
[1, 2, 3],
[4, [5, 6], 7],
[[8, 9], 10, [11, 12, 13, 14]],
15,
[16, 17, [18, 19], 20]
]
def walk(data):
for el in data:
if isinstance(el, (list, tuple)):
for sub_el in walk(el):
yield sub_el
else:
yield el
for i in walk(DATA):
print i
output:
$ python test_breadth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment