Design Pattern Examples
Overview of object-oriented design patterns
iterator_exercise.py
Go to the documentation of this file.
6
7from .iterator_class import IteratorContainer_Class
8
9
16
17# ! [Using Iterator in Python]
19 print()
20 print("Iterator Exercise")
21
22 # For this example, the class already has built into it the data
23 # to be iterated over.
25
26 print(" Iterating over keys only:")
27 keyIterator = items.GetKeys()
28 item = keyIterator.Next()
29 while item:
30 print(" {0}".format(item))
31 item = keyIterator.Next()
32
33 print(" Iterating over values only:")
34 valueIterator = items.GetValues()
35 value = valueIterator.Next()
36 while value:
37 print(" {0}".format(value))
38 value = valueIterator.Next()
39
40 print(" Iterating over all items:")
41 itemIterator = items.GetItems()
42 key_value_pair = itemIterator.Next()
43 while key_value_pair:
44 print(" {0} = {1}".format(key_value_pair.Key, key_value_pair.Value))
45 key_value_pair = itemIterator.Next()
46
47 print(" Done.")
48# ! [Using Iterator in Python]
Represents a container that offers up two kinds of iterators for the hardcoded contents,...
def Iterator_Exercise()
Example of using the Iterator Pattern.