[Python-ideas] [Python-Dev] hello, new dict addition for new eve ?
Nathan Rice
nathan.alexander.rice at gmail.com
Tue Jan 3 22:25:44 CET 2012
On Tue, Jan 3, 2012 at 4:02 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 1/3/2012 11:59 AM, Nathan Rice wrote:
>>
>> This is slightly tangential, but I've always wondered... Why aren't
>> set operations implemented on dicts? It is fairly natural to view a
>> dictionary as a set of (key, value) pairs. Things like
>> subset/superset checking (with concomitant operator support) make
>> sense. I have written stuff like set(dict1.items())<
>> set(dict2.items()) many times.
>
>
> As a said earlier in this thread, being able to view dicts as sets is such a
> good idea that it was already added a few years ago.
>
>>>> {1:1}.items() < {1:1, 2:2}.items()
> True
Yes, my apologies, I knew about views but I missed the part where they
have set operations. I was under the impression when I wrote that
they were just plain iterators. I try to keep current on Py3 nuances,
but since my work ties me to Py2, I will miss subtle but important
points like that from time to time. I still don't think there is
anything wrong with having the comparison operations present on the
dictionary directly, it seems intuitive *to me*. Of course I
understand that I may be an outlier in this (and it certainly wouldn't
be the first time :P).
Nathan
More information about the Python-ideas
mailing list