[Python-ideas] Adding "+" and "+=" operators to dict

Thomas Kluyver thomas at kluyver.me.uk
Thu Feb 12 19:49:49 CET 2015


On 12 February 2015 at 10:27, Ethan Furman <ethan at stoneleaf.us> wrote:

> If we go with "updated" then it should be a separate function, like
> "sorted" and "reveresed" are.


Arguments that it should be a method on mappings:

1. It's less generally applicable than sorted() or reversed(), which work
for any finite iterable.
2. As a method on the object, it's very clear how it works with different
types - e.g. Counter.updated() uses Counter.update(). This is less clear if
it's based on the first argument to a function.
2a. You can do dict.update(counter_object, foo) to use the dict method on a
Counter instance.
3. updated() as a standalone name is not very obvious - people think of how
to 'combine' or 'merge' dicts, perhaps 'union' if they're of a mathematical
bent. The symmetry between dict.update() and dict.updated() is clearer.
4. Set operations are defined with methods on set objects, not standalone
functions. This seems roughly analogous.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150212/873c64af/attachment.html>


More information about the Python-ideas mailing list