Created
June 11, 2018 14:56
-
-
Save Fhernd/e07a233f0cc7efffbeba968a5c3ca7e4 to your computer and use it in GitHub Desktop.
Delegación iteración. 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
class Nodo: | |
def __init__(self, valor): | |
self.valor = valor | |
self._hijos = [] | |
def __repr__(self): | |
return 'Nodo({!r})'.format(self.valor) | |
def agregar_hijo(self, nodo): | |
self._hijos.append(nodo) | |
def __iter__(self): | |
return iter(self._hijos) | |
if __name__ == '__main__': | |
raiz = Nodo(0) | |
hijo1 = Nodo(1) | |
hijo2 = Nodo(2) | |
raiz.agregar_hijo(hijo1) | |
raiz.agregar_hijo(hijo2) | |
for hijo in raiz: | |
print(hijo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment