Advertisement
Fhernd

allanar-secuencias-anidadas.py

Jun 26th, 2018
1,660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. from collections import Iterable
  2.  
  3. def allanar_coleccion(elementos, tipos_omitidos=(bytes, str)):
  4.     for elmt in elementos:
  5.         if isinstance(elmt, Iterable) and not isinstance(elmt, tipos_omitidos):
  6.             yield from allanar_coleccion(elmt)
  7.         else:
  8.             yield elmt
  9.  
  10. elementos = [[1,'a',['cat'],2],[[[3]],'dog'],4,5]
  11.  
  12. for elmt in allanar_coleccion(elementos):
  13.     print(elmt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement