
Can't "|" return a view? On Thursday, February 12, 2015 at 9:53:12 AM UTC-5, Petr Viktorin wrote:
I don't see ChainMap mentioned in this thread, so I'll fix that:
On Thu, Feb 12, 2015 at 2:32 PM, Juancarlo Añez <apa...@gmail.com <javascript:>> wrote:
most common cases would be:
new_dict = a + b old_dict += a
In today's Python, that's: from collections import ChainMap new_dict = dict(ChainMap(b, a)) old_dict.update(a)
new_dict = {} for old_dict in (a, b, c, d): new_dict.update(old_dict)
It would be easier if we could do:
new_dict = {} new_dict.update(a, b, c, d)
It would also be useful if dict.update() returned self, so this would be valid:
new_dict = {}.update(a, b, c, d)
In today's Python: new_dict = dict(ChainMap(d, b, c, a))
Many uses don't need the dict() call – e.g. when passing it **kwargs, or when it's more useful as a view.
Personally, the lack of a special operator for this has never bothered me. _______________________________________________ Python-ideas mailing list Python...@python.org <javascript:> https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/