Set Operations on Dicts

Ian Kelly ian.g.kelly at gmail.com
Tue Feb 9 10:14:15 EST 2016


On Tue, Feb 9, 2016 at 12:21 AM, Grobu <snailcoder at retrosite.invalid> wrote:
> On 08/02/16 17:12, Ian Kelly wrote:
>
>> dict does already expose set-like views. How about:
>>
>> {k: d[k] for k in d.keys() & s}  # d & s
>> {k: d[k] for k in d.keys() - s}  # d - s
>>
> Interesting. But seemingly only applies to Python 3.

Substitute d.viewkeys() for d.keys() in Python 2.7.


More information about the Python-list mailing list