Guest User

Untitled

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