design-patterns/behavioral/iterator/main.py
Ruidy a4cc9340b7
Iterator (#17)
* doc: add documentation

* doc: update tocs

* add code example
2020-10-02 15:24:36 +02:00

17 lines
512 B
Python

"""
The client code may or may not know about the Concrete Iterator or Collection
classes, depending on the level of indirection you want to keep in your program.
"""
from behavioral.iterator.alpha_order_iterator import WordCollection
collection = WordCollection()
collection.add_item("First")
collection.add_item("Second")
collection.add_item("Third")
print("Straight traversal:")
print("\n".join(collection))
print("")
print("Reverse traversal:")
print("\n".join(collection.get_reverse_iterator()), end="")