Created
January 24, 2019 21:51
-
-
Save mpapierski/cce81596b73da5840fea1127fe8b2ca2 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
#!/usr/bin/env python3 | |
from collections.abc import Iterable | |
data = [1,2,[3,4,[5,6,[7,8,[9,10,[[[11],12],[13,14,15]]]]]]] | |
def flatten(data): | |
for value in data: | |
if isinstance(value, (Iterable,)): | |
# Call recursively to yield nested values from | |
yield from flatten(value) | |
else: | |
# Any other type yields its value | |
yield value | |
for value in flatten(data): | |
print(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment