[Python-ideas] Adding "+" and "+=" operators to dict
Juancarlo Añez
apalala at gmail.com
Thu Feb 12 14:32:04 CET 2015
On Thu, Feb 12, 2015 at 6:13 AM, Steven D'Aprano <steve at pearwood.info>
wrote:
> I certainly wouldn't want to write
>
> new_dict = a + b + c + d
>
> and have O(N**2) performance when I can do this instead
>
It would likely not be O(N), but O(N**2) seems exaggerated. Besides, the
most common cases would be:
new_dict = a + b
old_dict += a
Both of which can be had in O(N).
>
> 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)
If that was so, then '+' could perhaps be implemented in terms of update()
with the help of some smarts from the parser.
Cheers,
--
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150212/af484513/attachment.html>
More information about the Python-ideas
mailing list