27.02.19 20:48, Guido van Rossum пише:

On Wed, Feb 27, 2019 at 10:42 AM Michael Selik <m...@selik.org <mailto:m...@selik.org>> wrote > The dict subclass collections.Counter overrides the update method
    for adding values instead of overwriting values.

    
https://docs.python.org/3/library/collections.html#collections.Counter.update

    Counter also uses +/__add__ for a similar behavior.

         >>> c = Counter(a=3, b=1)
         >>> d = Counter(a=1, b=2)
         >>> c + d # add two counters together:  c[x] + d[x]
         Counter({'a': 4, 'b': 3})

    At first I worried that changing base dict would cause confusion for
    the subclass, but Counter seems to share the idea that update and +
    are synonyms.


Great, this sounds like a good argument for + over |. The other argument is that | for sets *is* symmetrical, while + is used for other collections where it's not symmetrical. So it sounds like + is a winner here.

Counter uses + for a *different* behavior!

>>> Counter(a=2) + Counter(a=3)
Counter({'a': 5})

I do not understand why we discuss a new syntax for dict merging if we already have a syntax for dict merging: {**d1, **d2} (which works with *all* mappings). Is not this contradicts the Zen?

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to