intersection, union, difference, symmetric difference for dictionaries

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Feb 25 17:35:00 EST 2014


On 25/02/2014 22:11, mauro wrote:
>
>>
>> {1, 2} & {2, 3} == {2}
>>
> In my mind the intersection is evaluated on keys, so the resulting dict
> should be the empty one
>> but
>>
>> {1:"a", 2:"b", 3:"c"} & {2:"b", 3:"e", 4:"f"} == ???
> my output will be
> {2:"b", 3:"e"}
> or
> {2:"b", 3:"c"}
>
> depending on the implementation choice.
>>
>> The most obvious result is probably the empty dict {2:"b"}, i. e.
>>
>> a & b is defined as dict(a.items() & b.items())
>>
>> Frankly, I don't do that a lot. So what's your use-case?
> I do not have an use case, but I've seen that many people ask for these
> operations for example in stackoverflow.com
>

Please ask one of the many people on stackoverflow to raise an 
enhancement request here bugs.python.org complete with a patch that 
changes code, docs and tests and then everybody will be happy, won't they.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com





More information about the Python-list mailing list