[New-bugs-announce] [issue32617] dict.update does not concat/replace if same key

Avnish Midha report at bugs.python.org
Mon Jan 22 01:22:13 EST 2018


New submission from Avnish Midha <avnishbm10 at gmail.com>:

The dict does not seem to work as one would expect a dictionary or a hashtable to work. 

dict.update(otherdict) just replaces the entries as per otherdict, removing items which were extra in dict too and just keeping items as per new data in otherdict only. Shouldn't this be actually about updating the dict with new/updated entries and not touching those entries which pre-existed?

Sample program below:
import pandas as pd

x = {'name': ['A', 'B', 'C'], 'col2': [3, 4,6]}
y = {'name': ['B', 'C', 'D', 'E'], 'col2': [1,2, 9, 10]}


print ("X = \n" + str(x))

print ("Y = \n" + str(y))

x.update(y)

print ("updated dict = \n"  + str(x) + "\n")

#####

Output:

X = 
{'name': ['A', 'B', 'C'], 'col2': [3, 4, 6]}
Y = 
{'name': ['B', 'C', 'D', 'E'], 'col2': [1, 2, 9, 10]}
updated dict = 
{'name': ['B', 'C', 'D', 'E'], 'col2': [1, 2, 9, 10]}


Expected value:
updated dict = 
{'name': ['A','B', 'C', 'D', 'E'], 'col2': [3, 1, 2, 9, 10]}


Somehow to do this basic hashtable or dictionary update kind of operation is too complex in python and update() should have actually functioned as expected above IMO.

----------
components: Interpreter Core
files: dict_try.py
messages: 310397
nosy: Avnish Midha
priority: normal
severity: normal
status: open
title: dict.update does not concat/replace if same key
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file47400/dict_try.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32617>
_______________________________________


More information about the New-bugs-announce mailing list