Python has this feature built-in:
>>> d = {'b': 4}
>>> d.update({'a': 2})
>>> d
{'a': 2, 'b': 4}
Or given you’re not allowed to use dict.update
:
>>> d = dict(d.items() + {'a': 2}.items()) # doesn't work in python 3
Python has this feature built-in:
>>> d = {'b': 4}
>>> d.update({'a': 2})
>>> d
{'a': 2, 'b': 4}
Or given you’re not allowed to use dict.update
:
>>> d = dict(d.items() + {'a': 2}.items()) # doesn't work in python 3