Next / Previous / Contents / TCC Help System / NM Tech homepage

4.26. SkipList.__contains__()

This special method is called when the user uses the Python “in” or “not in” operators to test whether a given key value matches any of the child objects in the skip list.

pyskip.py
# - - -   S k i p L i s t . _ _ c o n t a i n s _ _   - - -

    def __contains__ ( self, key ):
        """Does self contain the given key?"""

First we call the .match() method to tell us whether there's a matching element. Then we convert the return values of that method to a Boolean.

pyskip.py
        #-- 1 --
        try:
            child  =  self.match ( key )
            return 1
        except KeyError:
            return 0