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

Thorsten Kampe thorsten at thorstenkampe.de
Sat Oct 19 16:22:12 CEST 2002


* Tim Peters
> [Thorsten Kampe]
>> #v+
>> if dict0 > dict1:  # loop through the shorter dict
>
> Obvious is better than obscure:
>
>    if len(dict0) > len(dict1):
>
> is what you mean, so why not just say so? You're not saving any
> measurable time by being tricky here, and, to the contrary, if the
> lengths happen to be the same, it can be unboundedly slower to
> compare the dicts by value instead of by length.

You're right. I changed the code, it was an inadequate desire for
brevity.

Thorsten



More information about the Python-list mailing list