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
  • 50,627
  • 10
  • 99
  • 112
Peri Javia
  • 131
  • 1
  • 1
  • 9

0 Answers0