11#!/usr/bin/env python
22# Written by: DGC
33
4- import abc
4+ #
5+ ##==============================================================================
6+ #class ImmutableContainer(object):
7+ # __metaclass__ = abc.ABCMeta
8+ #
9+ # @abc.abstractmethod
10+ # def __len__(self):
11+ # raise
12+ #
13+ # @abc.abstractmethod
14+ # def __getitem__(self, key):
15+ # raise
16+ #
17+ ##==============================================================================
18+ #class MutableContainer(ImmutableContainer):
19+ # __metaclass__ = abc.ABCMeta
20+ #
21+ # @abc.abstractmethod
22+ # def __setitem__(self, key, value):
23+ # raise
24+ #
25+ # @abc.abstractmethod
26+ # def __delitem__(self, key):
27+ # raise
28+ #
29+ ##==============================================================================
30+ #class Iterable(object):
31+ # __metaclass__ = abc.ABCMeta
32+ #
33+ # @abc.abstractmethod
34+ # def __iter__(self):
35+ # raise
536
637#==============================================================================
7- class ImmutableContainer (object ):
8- __metaclass__ = abc .ABCMeta
9-
10- @abc .abstractmethod
11- def __len__ (self ):
12- raise
13-
14- @abc .abstractmethod
15- def __getitem__ (self , key ):
16- raise
17-
18- #==============================================================================
19- class MutableContainer (ImmutableContainer ):
20- __metaclass__ = abc .ABCMeta
21-
22- @abc .abstractmethod
23- def __setitem__ (self , key , value ):
24- raise
25-
26- @abc .abstractmethod
27- def __delitem__ (self , key ):
28- raise
29-
30- #==============================================================================
31- class Iterable (object ):
32- __metaclass__ = abc .ABCMeta
33-
34- @abc .abstractmethod
35- def __iter__ (self ):
36- raise
37-
38- #==============================================================================
39- class ReverseIterator (Iterable ):
38+ class ReverseIterator (object ):
4039 """
4140 Iterates the object given to it in reverse so it shows the difference.
4241 """
@@ -51,15 +50,18 @@ def __iter__(self):
5150 return self
5251
5352 def next (self ):
54- " Return the list backwards so it's noticably different."
53+ """ Return the list backwards so it's noticably different."" "
5554 if (self .index == 0 ):
5655 # the list is over, raise a stop index exception
5756 raise StopIteration
5857 self .index = self .index - 1
5958 return self .list [self .index ]
6059
61- if (__name__ == "__main__" ):
62- days = [
60+ #==============================================================================
61+ class Days (object ):
62+
63+ def __init__ (self ):
64+ self .days = [
6365 "Monday" ,
6466 "Tuesday" ,
6567 "Wednesday" ,
@@ -68,6 +70,11 @@ def next(self):
6870 "Saturday" ,
6971 "Sunday"
7072 ]
71- it = ReverseIterator (days )
72- for day in it :
73+
74+ def reverse_iter (self ):
75+ return ReverseIterator (self .days )
76+
77+ if (__name__ == "__main__" ):
78+ days = Days ()
79+ for day in days .reverse_iter ():
7380 print (day )
0 commit comments