Why aren't OrderedDicts comparable with < etc?
Mark Summerfield
list at qtrac.plus.com
Thu Jul 16 02:21:48 EDT 2009
Hi,
I'm just wondering why <, <=, >=, and > are not supported by
collections.OrderedDict:
>>> d1 = collections.OrderedDict((("a",1),("z",2),("k",3)))
>>> d2 = d1.copy()
>>> d2["z"] = 4
>>> d1 == d2
False
>>> d1 < d2
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
d1 < d2
TypeError: unorderable types: OrderedDict() < OrderedDict()
It just seems to me that since the items in ordered dictionaries are
ordered, it would make sense to do an item by item comparison from
first to last item in exactly the same way that Python compares lists
or tuples?
More information about the Python-list
mailing list