Why aren't OrderedDicts comparable with < etc?

Nobody nobody at nowhere.com
Thu Jul 16 23:12:32 CEST 2009

On Thu, 16 Jul 2009 03:59:47 -0700, Mark wrote:

>> > Or maybe not. If OrderedDicts are sequences as well as mappings, then we
>> > should be able to sort them. And that seems a bit much even for me.

>> One thing that I've just noticed is that you can use <, <=, >=, and >
>> with sets:

>> It seems a bit inconsistent that with sets you always get False when
>> using an ordering operator but with an ordered dict you get an
>> exception?
> Ooops---disregard the above---I forgot that these do subset and
> superset comparisions!

Which is an argument for dictionaries (ordered or not) doing likewise,
except that the comparison would be subfunction rather than subset,
i.e. d1<d2 = all(k in d2 and d2[k] == d1[k] for k in d1).

More information about the Python-list mailing list