Re: dictionary interface
- From: Antoon Pardon <apardon@xxxxxxxxxxxxxxx>
- Date: 5 Oct 2005 10:04:20 GMT
Op 2005-10-05, Steve Holden schreef <steve@xxxxxxxxxxxxx>:
> Antoon Pardon wrote:
>>
>> I have been searching some more and finally stumbled on this:
>>
>> http://docs.python.org/ref/comparisons.html
>>
>> Mappings (dictionaries) compare equal if and only if their sorted
>> (key, value) lists compare equal. Outcomes other than equality are
>> resolved consistently, but are not otherwise defined.
>>
>> This seems to imply that the specific method to sort the dictionaries
>> is unimported (as long as it is a total ordering). So I can use whatever
>> method I want as long as it is achieves this.
>>
>> But that is contradicted by the unittest. If you have a unittest for
>> comparing dictionaries, that means comparing dictionaries has a
>> testable characteristic and thus is further defined.
>>
>> So I don't need a full implementation of dictionary comparison,
>> I need to know in how far such a comparison is defined and
>> what I can choose.
>>
> The dict unit tests are probably trying to ensure that the dictionary
> ordering doesn't change from version to version, which is probably a
> good idea in case someone (foolishly?) deciess to rely on it.
I doubt that. Just to check I tried the following:
class Tree:
def __lt__(self, term):
return len(self) < len(term)
And the test passed.
> I can't help wondering, though, under what conditions it actually makes
> sense to compare two dictionaries for anything other than equality.
Yes that is part of the problem, because I can't think of such a
condition it is hard to think of what extra constraints could be
usefull here.
Anyway, I have searched the source of the test for all testing
with regards to < and after some browsing back and fore it seems
it all boils down to the following two tests.
self.assert_(not {} < {})
self.assert_(not {1: 2} < {1L: 2L})
--
Antoon Pardon
.
- Follow-Ups:
- Re: dictionary interface
- From: Steve Holden
- Re: dictionary interface
- References:
- dictionary interface
- From: Antoon Pardon
- Re: dictionary interface
- From: Robert Kern
- Re: dictionary interface
- From: Tom Anderson
- Re: dictionary interface
- From: Antoon Pardon
- Re: dictionary interface
- From: Steve Holden
- dictionary interface
- Prev by Date: Re: "no variable or argument declarations are necessary."
- Next by Date: sos too long penis
- Previous by thread: Re: dictionary interface
- Next by thread: Re: dictionary interface
- Index(es):
Relevant Pages
|