[issue21678] Add operation plus for dictionaries

2014-06-06 Thread Михаил Мишакин

New submission from Михаил Мишакин:

First of all, i'm sorry for my English :)

I would like to union dictionaries with operator + (and +=) like this:

 dict(a=1, b=2) + {'a': 10, 'c': 30}
{'a': 10, 'b': 2, 'c': 30}

 d = dict(a=1, b=2, c={'c1': 3, 'c2': 4})
 d += dict(a=10, c={'c1':30})
 d
{'a': 10, 'b': 2, c: {'c1':30}}


Also, it gives an easy way to modify and extend the class attributes:

class Super:
   params = {
   'name': 'John',
   'surname': 'Doe',
   }

class Sub(Super):
   params = Super.params + {
   'surname': 'Show',
   'age': 32,
   }

--
components: Interpreter Core
messages: 219867
nosy: Pix
priority: normal
severity: normal
status: open
title: Add operation plus for dictionaries
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21678] Add operation plus for dictionaries

2014-06-06 Thread STINNER Victor

STINNER Victor added the comment:

You should use dict.update() method.

--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21678] Add operation plus for dictionaries

2014-06-06 Thread Михаил Мишакин

Михаил Мишакин added the comment:

Is's like list's operation + and it's method list.extend().
But dict have no operation +...

If I have two lists (A and B), and I want to get third list (not change A and 
B) i do this:
C = A + B

If I have two dicts, i can do this:
C = dict(A, **B)

But if i have three dictionaries, code becomes this:
C = dict(A, **dict(B, **D))

Don't you think, that + is more comfortable?
A = [1, 2, 3]
B = [4, 5]
C = [6, 7]
A + B + C = [1,2,3,4,5,6,7]

I can do this with list, tuples and strings. Why i can't do this with 
dictionaries?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21678] Add operation plus for dictionaries

2014-06-06 Thread Terry J. Reedy

Terry J. Reedy added the comment:

This has been proposed, discussed on both python-list and python-ideas, and 
rejected more than once because there are there are multiple possible response 
to multiple keys: keep first value, keep second value (.update), keep both (in 
a list), or keep neither and raise.

'Obvious' ideas like this should be floated on one of those two lists to find 
out past response.

--
nosy: +terry.reedy
resolution:  - rejected
stage:  - resolved
status: open - closed
type:  - enhancement
versions: +Python 3.5 -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com