
On Mon, Dec 2, 2019 at 8:39 PM Kyle Stanley <aeros167@gmail.com> wrote:
Also, I think it's worth noting that we can optimize the actual behavior of the in-place operator under the hood, similar to what is done with consecutive string concatenations [2]. Of course, the optimization wouldn't be the same as it is with strings (since strings are immutable and dicts are mutable), but it still works as an example. IMO, that's a significant benefit of high-level languages such as Python: we can simplify the syntax while optimizing the exact behavior in the internals.
Actually there's no need to optimize the |= operator -- for strings we have to optimize += *because* strings are immutable, but for dicts we would define |= as essentially an alias for .update(), just like the relationship between += and .extend() for lists, and then no unnecessary objects would be created. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>