Created
May 22, 2013 19:05
-
-
Save james-m/5630053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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