Created
April 26, 2020 03:18
-
-
Save ryanpeach/e57a5e17cdc685b734351a4d5f8bd3c7 to your computer and use it in GitHub Desktop.
Flatten
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
import collections | |
def flatten(l): | |
for el in l: | |
if isinstance(el, collections.Iterable) and not isinstance(el, (str, bytes)): | |
yield from flatten(el) | |
else: | |
yield el |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment