Josh Rosenberg added the comment:
That's the expected behavior, and it's clearly documented here:
https://docs.python.org/3/library/stdtypes.html#dict.fromkeys
Quote: "All of the values refer to just a single instance, so it generally
doesn’t make sense for value to be a mutable object such a
sourya varenya added the comment:
Here's a sample run for reproducibility:
---
Python 3.6.9(Ubuntu 18.04) & 3.7.4(Windows)
---
>>> a = {1:{5:8},2:{5:8}}
>>> b = dict.fromkeys([1,2],{5:8})
>>> a
{1: {5: 8}, 2: {5: 8}}
>>> b
{1: {5: 8}, 2: {5: 8}}
>>> a[1].update({6:9})
>>> b[1].update({6:9})
New submission from sourya varenya :
Here's a sample run for reproducibility:
---
Python 3.6.9(Ubuntu 18.04) & 3.7.4(Windows)
---
>>> a = {1:{5:8},2:{5:8}}