Last active
December 29, 2015 04:59
-
-
Save dnmellen/7618531 to your computer and use it in GitHub Desktop.
My try for "flatten" with yield from
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
from collections import Iterable | |
def flatten(iterable): | |
for item in iterable: | |
if isinstance(item, Iterable): | |
yield from flatten(item) | |
else: | |
yield item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment