Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 26, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/739821af1623aec2490c5ead7f32fba7 to your computer and use it in GitHub Desktop.
Save Fhernd/739821af1623aec2490c5ead7f32fba7 to your computer and use it in GitHub Desktop.
Allanar colección con secuencias anidadas. OrtizOL.
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