dict1 < dict2 <=> len(dict1) <= len(dict2) ?

Thorsten Kampe thorsten at thorstenkampe.de
Fri Oct 18 18:28:55 EDT 2002


* Tim Peters
> [Thorsten Kampe]
>> does anyone know what "dict1 < dict2" tests?
[...]
>> I think it's equivalent to "len(dict1) <= len(dict2)", but I could
>> be wrong.
>
> Partly. len(d1) < len(d2) implies d1 < d2 in recent Python releases,
> but it's much more complicated if len(d1) == len(d2).
[...]
> It's too tedious to explain the full truth here, and it doesn't
> matter (if you think it does, you're writing code nobody will
> understand!).

Of course I didn't understand everything you said, but in my case it
doesn't matter. I just wanted to make sure that this code snippet (see
above) does what I hoped it would.

And with the "#" comment I hope no one will accuse me of writing
perlish Python ;-)

#v+
if dict0 > dict1:  # loop through the shorter dict
    dict0, dict1 = dict1, dict0
for item in dict0:
#v-


Thorsten



More information about the Python-list mailing list