Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Iterable
- def flatten(items):
- """Yield items from any nested iterable; see REF."""
- for x in items:
- if isinstance(x, Iterable) and not isinstance(x, (str, bytes)):
- yield from flatten(x)
- else:
- yield x
- arr = [[1, [2]], (3, 4, {5, 6}, 7), 8, "9"]
- list(flatten(arr))
Add Comment
Please, Sign In to add comment