Created
June 27, 2016 12:43
-
-
Save Makistos/f7ba2e279e38019be0d0531b0f0a8a98 to your computer and use it in GitHub Desktop.
Flattening a list in Python. #python
This file contains hidden or 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
def flatten(coll): | |
for i in coll: | |
if isinstance(i, (list, tuple)): | |
for j in flatten(i): | |
yield j | |
else: | |
yield i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment