Next / Previous / Contents / Shipman's homepage

22.7. YearRow.successor(): Find the following month

This method is the mirror image of Section 22.6, “YearRow.predecessor(): Find the previous month”. The only difference is that we sort the key list in ascending order instead of descending.

noteweb
# - - -   Y e a r R o w . s u c c e s s o r

    def successor ( self, mm ):
        '''Find the following month.
        '''
        #-- 1 --
        # [ mmList  :=  keys of self.__monthMap in ascending order ]
        mmList  =  self.__monthMap.keys()
        mmList.sort()

        #-- 2 --
        # [ mm is a member of mmList ->
        #     pos  :=  position of mm in mmList ]
        pos  =  mmList.index ( mm )

        #-- 3 --
        # [ if pos+1 >= len(mmList) ->
        #     raise KeyError
        #   else ->
        #     return mmList[pos+1] ]
        if  pos+1 >= len(mmList):
            raise KeyError
        else:
            return mmList[pos+1]