So I try to make a deepcopy of dict and update it with some additional data (I don't want to change my original dict):
>>> a = {1:1}
>>> print(a)
{1: 1}
>>> b = copy.deepcopy(a).update({2:2})
>>> print(b)
None
But when I do it in another way, it works:
>>> a = {1:1}
>>> b = copy.deepcopy(a)
>>> b.update({2:2})
>>> print(b)
{1: 1, 2: 2}
Why Python sets b
variable to None
when I update on same line?
I've also try to make deepcopy of original dict:
>>> a = {1:1}
>>> a = copy.deepcopy(a).update({2:2})
>>> print(a)
None
But:
>>> a = {1:1}
>>> a = copy.deepcopy(a)
>>> a
{1: 1}
So this is dict.update
issue? Or maybe it's CPython related behavior?