(original) (raw)

+1 for adding "+" or "|" operator for merging dicts. To me this operation:

>>> {'x': 1, 'y': 2} + {'z': 3}
{'x': 1, 'y': 2, 'z': 3}

Is very clear. The only potentially non obvious case I can see then is when there are duplicate keys, in which case the syntax could just be defined that last setter wins, e.g.:

>>> {'x': 1, 'y': 2} + {'x': 3}
{'x': 3, 'y': 2}

Which is analogous to the example:

new\_dict = dict1.copy()
new\_dict.update(dict2)


\~ Ian Lee

On Tue, Feb 10, 2015 at 12:11 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
On 10.02.15 04:06, Ethan Furman wrote:
return func(\*(args + fargs), \*\*{\*\*keywords, \*\*fkeywords})

We don't use \[\*args, \*fargs\] for concatenating lists, but args + fargs. Why not use "+" or "|" operators for merging dicts?



\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/ianlee1521%40gmail.com