On Wed, Jul 24, 2019 at 12:36:29PM +0200, Ronald Oussoren wrote:
> 
> 
> Op 24 jul. 2019 om 02:27 heeft Steven D'Aprano <st...@pearwood.info> het 
> volgende geschreven:
> 
> > But I can suggest at least one useful invariant. If a, b are two dicts:
> > 
> >    a.items() == b.items()
> > 
> > ought to be equivalent to:
> > 
> >    (a.keys() == b.keys()) and (a.values() == b.values)
> 
> I don’t think this invariant holds unless comparison is order dependent.  
> {1:2, 3:4} and {1:4, 3:2} have the same keys and values, but not the same 
> items.  

You are right, they aren't equivalent, that was the wrong term to use.

But not because of dependency on order. They aren't equivalent because 
you can have two dicts where the keys are equal and the values are 
equal, but the items are not:

a = {1: 'a', 2: 'b', 3: 'c'}
b = {1: 'a', 2: 'c', 3: 'b'}

Both dicts have keys {1, 2, 3} and hence equal keys;

both have values {'a', 'b', 'c'} and hence equal values;

but the items are not equal.

So the invariant only goes one way, not both:

(1) items equal implies values (and keys) are also equal;

(2) but values and keys equal doesn't imply items are equal.

But for our purposes, we don't care about case (2) and it doesn't matter 
that it doesn't hold.




-- 
Steven
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/PA5Z4PL3RZXEBS6WKTLGGGLNBTNNDAXU/

Reply via email to