dictionary interface

Antoon Pardon apardon at forel.vub.ac.be
Tue Oct 4 08:55:41 EDT 2005


I'm writing a Tree class, which should behave a lot like a dictionary.

In order to test this, I took the unittest from the source distribution
for dictionaries and used it to test against my Tree class.

Things are working out rather well, but I stumbled on a problem.

this unittest tries to test for '==' and '<' operators. However I
couldn't find anything in the documentation that defined how
dictionaries should behave with respect to these operators.

For the moment the best I can come up with is something like
the following:

  class Tree:

    def __lt__(self, term):
      return set(self.iteritems()) < set(term.iteritems())

    def __eq__(self, term):
      return set(self.iteritems()) == set(term.iteritems())

Would this be a correct definition of the desired behaviour?

Anyone a reference?

-- 
Antoon Pardon



More information about the Python-list mailing list