Advertisement
Fhernd

delegacion-iteracion.py

Jun 11th, 2018
1,912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. class Nodo:
  2.     def __init__(self, valor):
  3.         self.valor = valor
  4.         self._hijos = []
  5.  
  6.     def __repr__(self):
  7.         return 'Nodo({!r})'.format(self.valor)
  8.  
  9.     def agregar_hijo(self, nodo):
  10.         self._hijos.append(nodo)
  11.  
  12.     def __iter__(self):
  13.         return iter(self._hijos)
  14.  
  15. if __name__ == '__main__':
  16.     raiz = Nodo(0)
  17.     hijo1 = Nodo(1)
  18.     hijo2 = Nodo(2)
  19.  
  20.     raiz.agregar_hijo(hijo1)
  21.     raiz.agregar_hijo(hijo2)
  22.  
  23.     for hijo in raiz:
  24.         print(hijo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement