This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: limit dict.update() to a given list of keys
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Ultrasick, benjamin.peterson, rhettinger
Priority: normal Keywords:

Created on 2010-08-28 17:00 by Ultrasick, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg115157 - (view) Author: (Ultrasick) Date: 2010-08-28 17:00
my_dict_1 = {'a' : 1, 'b' : 1}
my_dict_2 = {'a' : 2, 'b' : 2, 'c' : 2}

my_dict_1.update(my_dict_2, ['a', 'c'])

should result for my_dict_1:

{'a' : 2, 'b' : 1, 'c' : 2}
msg115160 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-08-28 17:31
Please post to python-ideas first, and note a moratorium on builtin changes is inplace.
msg115167 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-08-28 20:02
FWIW, the usual way to spell this in Python is:

 my_dict_1.update((k, my_dict_2[k]) for k in ['a', 'c'])

We try to keep filtering operations separate from map/fold operations for orthognality.
History
Date User Action Args
2022-04-11 14:57:05adminsetgithub: 53914
2010-08-28 20:02:50rhettingersetnosy: + rhettinger
messages: + msg115167
2010-08-28 17:31:09benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg115160

resolution: rejected
2010-08-28 17:00:55Ultrasickcreate