[Python-Dev] (no subject) (original) (raw)
John Wong gokoproject at gmail.com
Wed Feb 11 07:35:17 CET 2015
- Previous message: [Python-Dev] (no subject)
- Next message: [Python-Dev] (no subject)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Feb 11, 2015 at 12:35 AM, Ian Lee <ianlee1521 at gmail.com> wrote:
+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: newdict = dict1.copy() newdict.update(dict2)
Well looking at just list a + b yields new list a += b yields modified a then there is also .extend in list. etc.
so do we want to follow list's footstep? I like + because + is more natural to read. Maybe this needs to be a separate thread. I am actually amazed to remember dict + dict is not possible... there must be a reason (performance??) for this... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150211/707deb35/attachment.html>
- Previous message: [Python-Dev] (no subject)
- Next message: [Python-Dev] (no subject)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]