Stefan Behnel <[email protected]> added the comment:
> We already have a syntax for dict merging: {**d1, **d2}.
Which doesn't mean that "d1 + d2" isn't much more intuitive than this
special-character heavy version. It takes me a while to see the dict merge
under that heap of stars. And that's already the shortest example.
> It works with arbitrary mappings,
The RHS of "d += M" doesn't have to be a dict IMHO, it could be any mapping.
And even "dict(X) + M" doesn't look all too bad to me, even though there's
"dict(X, **M)".
> Use of the + operator is a temptation to produce new dictionaries rather than
> update an existing dict in-place which is usually what you want.
That's why there would be support for "+=". The exact same argument already
fails for lists, where concatenation is usually much more performance critical
than for the average little dict. (And remember that most code isn't
performance critical at all.)
> We already have ChainMap() which presents a single view of multiple mappings
> with any copying.
Which is a different use case that is unlikely to go away with this proposal.
> makes it less clear that you're working with dicts.
This is a valid argument, although it always depends on the concrete code what
the most readable way to express its intentions is. Again, this doesn't really
differ for lists.
Let's wait for the PEP, I'd say.
----------
nosy: +scoder
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36144>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com