[Python-ideas] Dict joining using + and +=

Karthikeyan tir.karthi at gmail.com
Thu Feb 28 23:58:08 EST 2019


The PEP should probably also propose d1-d2.
>

What would be the output of this? Does this return a new dictionary where
keys in d2 are removed in d1 like sets?

>>> d = dict((i, i) for i in range(5))
>>> e = dict((i, i) for i in range(4, 10))
>>> d
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4}
>>> e
{4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9}
>>> d.items() - e.items()
{(0, 0), (1, 1), (3, 3), (2, 2)}
>>> dict(d.items() - e.items())
{0: 0, 1: 1, 3: 3, 2: 2}

-- 
Regards,
Karthikeyan S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190301/ac522201/attachment.html>


More information about the Python-ideas mailing list