Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs
[issue6410] Dictionaries should support __add__
 

Index | Next | Previous | View Flat


report at bugs

Jul 3, 2009, 1:33 PM


Views: 284
Permalink
[issue6410] Dictionaries should support __add__

New submission from Michael W. <hotdog003[at]gmail.com>:

Summary:
Dictionaries should support being added to other dictionaries instead of
using update(). This should be a relatively easy fix and would make the
language more pythonic.

How to reproduce:
$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> {1: 2, 3: 4} + {5: 6, 7: 8}

What happens:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'

What should happen:
{1: 2, 3: 4, 5: 6, 7: 8}

Temporary workaround:
>>> a = {1: 2, 3: 4}
>>> b = {5: 6, 7: 8}
>>> c = a.copy()
>>> c.update(b)
>>> print c
{1: 2, 3: 4, 5: 6, 7: 8}
This is undesirable because it is not very compact and hard to read. Why
should any language take five lines of code to merge only two dictionaries?

----------
components: Interpreter Core
messages: 90074
nosy: hotdog003
severity: normal
status: open
title: Dictionaries should support __add__
type: feature request
versions: Python 2.6

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue6410>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Subject User Time
[issue6410] Dictionaries should support __add__ report at bugs Jul 3, 2009, 1:33 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 3, 2009, 2:14 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 3, 2009, 2:37 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 3:34 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 3:39 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 4:27 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 4:37 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 4:38 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 4:51 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 5:23 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 8:26 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 4, 2009, 8:41 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 6, 2009, 2:23 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 6, 2009, 2:47 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 6, 2009, 4:59 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 6, 2009, 5:00 PM
    [issue6410] Dictionaries should support __add__ report at bugs Jul 10, 2009, 2:01 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.