[Python-ideas] PEP: Dict addition and subtraction

Jonathan Fine jfine2358 at gmail.com
Thu Mar 21 13:42:15 EDT 2019

Steven D'Aprano wrote:

> But if you have *concrete examples* of code that currently is easy to
> understand, but will be harder to understand if we add dict.__add__,
> then please do show me!

    # What does this do?
     >>> items. update(points)

    # And what does this do?
    >>> items += points

What did you get? Here's one possible context.

    >>> Point = namedtuple('Point', ['x', 'y'])
    >>> p, q, r = Point(1,2), Point(3, 4), Point(5, 6)
    >>> points = set([p, q, r])
    >>> points
    {Point(x=1, y=2), Point(x=5, y=6), Point(x=3, y=4)}
    >>> items = dict(a=4, b=8)

More information about the Python-ideas mailing list