Python culture runs counter to monkeypatching standard library
objects, but this looks be easy to do via injecting __add__ (and
__iadd__ for "d1 += d2") straight into the dict class. In Ruby it's
done  In fact it looks so obvious that ...

/me googles...

https://www.google.com.au/search?q=dict+__add__

The first result is a bug report, but it was rejected before it got to
PEP stage even: http://bugs.python.org/issue6410. Contains good
rationale for the rejection.

J

On Thu, Oct 17, 2013 at 11:31 AM, Sam Lai <[email protected]> wrote:
> It's almost Friday, so I have a question where I'm pretty sure I'm
> missing something obvious.
>
> Given,
>
> d1 = { 'a' : 'b' }
> d2 = { 'c' : 'd' }
>
> ...  why isn't d3 = d1 + d2 implemented to be equivalent to -
>
> d3 = { }
> d3.update(d1)
> d3.update(d2)
>
> It doesn't work for sets either, but it works in this fashion for
> lists. Is this because the operation is non-commutative for sets and
> dicts and may result in a loss of data when clashing keys are
> involved? Isn't that implicit when working with sets and dicts?
>
> Sam
> _______________________________________________
> melbourne-pug mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/melbourne-pug
_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to