In the code below, very strangely to me, 0 and 1 are added to the BOTH keys:
zip_to_dict1 = zip(["a", "b"], [[]]*2)
dict1 = dict(zip_to_dict1)
dict1["a"].append(0)
dict1["b"].append(1)
print(dict1["a"], dict1["b"])
# [0, 1] [0, 1]
However, this works somehow:
zip_to_dict2 = zip(["a", "b"], [[], []])
dict2 = dict(zip_to_dict2)
dict2["a"].append(0)
dict2["b"].append(1)
print(dict2["a"], dict2["b"])
# [0] [1]
Is there any difference between [[]]*2
and [[], []]
?:
[[]]*2 == [[], []]
# True
...What's the problem?
(Note: I'm using Python 3.4.1)