0

Python 3.6:

>>> x = [0, 1]
>>> y = [[]]*2
>>> z = dict(zip(x, y))
>>> z
{0: [], 1: []}
>>> z[0].append(0)
>>> z
{0: [0], 1: [0]}
>>>

Why did it append to both? I tried without zip and it worked fine. Please explain this behavior

jwodder
  • 54,758
  • 12
  • 108
  • 124
Peri Javia
  • 161
  • 1
  • 1
  • 9

0 Answers0