[Python-3000] dict view operations (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Tue Sep 4 21:22:48 CEST 2007


What use case are you thinking of that this would address? It would allow to treat the items view as a proper set (which it still is). Can you give some examples?

You mean, actual applications where people would want to perform set operations on .items()? No - I was just trying to give a solution to the theoretical problem that Georg brought up.

I can too easily think of examples that fail with this approach:

d = {1: 1, 2: 2} iv = set(d.items()) (1, 1) in iv The latter expression would be False, (while it currently is True), since (1,1) has a different hash value than Association((1, 1)).

Right. Since the elements in the view/set would not be plain two-tuples, this would have to be spelled as

Association((1,1)) in iv

Of course, it violates the principle that things that compare equal should also hash equal; to restore that principle, one would have to make associations not compare equal to two-tuples (and then not make them a subtype anymore, either).

Regards, Martin



More information about the Python-3000 mailing list