Antoon Pardon wrote:
> 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?

No.

In [1]: {1:2} < {3:4}
Out[1]: True

In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems())
Out[2]: False

> Anyone a reference?

The function dict_compare in dictobject.c .

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to