The problem is that update
mutates the dictionary it is not returning a dictionary. See in the docs that this method returns None
.
If you just want to have one line to solve your problem, you can solve this problem by:
some_list.append(dict({'new_key': 'new_value'}, **some_dict))
Also to keep in mind:
In Python 3.5+ you can do:
>>> params = {'a': 1, 'b': 2}
>>> new_params = {**params, **{'c': 3}}
>>> new_params
{'a': 1, 'b': 2, 'c': 3}
The Python 2 equivalent is:
>>> params = {'a': 1, 'b': 2}
>>> new_params = dict(params, **{'c': 3})
>>> new_params
{'a': 1, 'b': 2, 'c': 3}