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

Hans Nowak wurmy at earthlink.net
Fri Oct 18 16:29:58 EDT 2002


Thorsten Kampe wrote:

> Hi,
> 
> does anyone know what "dict1 < dict2" tests? I think it's equivalent
> to "len(dict1) <= len(dict2)", but I could be wrong.
> 
> "{111: 111} < {11:11, 22:22}" but "{111: 111, 22:22} > {11:11, 22:22}"
> made me guess: "'<' first tests the lengths and if they're the same
> the keys are compared".
> 
> Anyone who doesn't guess but /knows/?!

According to dictobject.c, this is indeed what happens. First the lengths are 
compared; if they're the same, the keys are compared.

Cheers,

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
Kaa:: http://www.awaretek.com/nowak/kaa.html




More information about the Python-list mailing list