Created
June 26, 2018 20:01
-
-
Save Fhernd/739821af1623aec2490c5ead7f32fba7 to your computer and use it in GitHub Desktop.
Allanar colección con secuencias anidadas. OrtizOL.
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 allanar_coleccion(elementos, tipos_omitidos=(bytes, str)): | |
for elmt in elementos: | |
if isinstance(elmt, Iterable) and not isinstance(elmt, tipos_omitidos): | |
yield from allanar_coleccion(elmt) | |
else: | |
yield elmt | |
elementos = [[1,'a',['cat'],2],[[[3]],'dog'],4,5] | |
for elmt in allanar_coleccion(elementos): | |
print(elmt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment