In python, I have a dictionary named dict_a :
dict_a = {'a':1}
and I want to get a new dictionary dict_b
as the update of dict_a
,at the same time I don't want to change the dict_a
, so I used this:
dict_b = copy.deepcopy(dict_a).update({'b':2})
However, the return value of dict.update
is None
, so the above code doesn't work. And I have to use this:
temp = copy.deepcopy(dict_a)
temp.update({'b':2})
dict_b = temp
The question is, how to get my goal in one line? Or some