I have created a list such as :
abc=[1,2,3,4,5,6]
Now I am creating two empty dictionaries where the key is a no. and value is an empty list.
aa=[i for i in range(0,30,6)]
diction=dict.fromkeys(aa,[])
Another dictionary is :
dict_test={i:[] for i in range(0,30,6)}
The two dictionaries are :
diction is {0:[],6:[],12:[],18:[],24:[]}
dict_test is {0:[],6:[],12:[],18:[],24:[]}
Here, dict_test==diction gives True
Now I just wish to append the values to one key only, therefore,I using a simple for loop :
for i in abc:
diction[0].append([i])
dict_test[0].append([i])
But weird behaviour is :
diction becomes :
{0: [[1], [2], [3], [4], [5], [6]],
6: [[1], [2], [3], [4], [5], [6]],
12: [[1], [2], [3], [4], [5], [6]],
18: [[1], [2], [3], [4], [5], [6]],
24: [[1], [2], [3], [4], [5], [6]]}
dict_test becomes :
{0: [[1], [2], [3], [4], [5], [6]], 6: [], 12: [], 18: [], 24: []}
dict_test is giving the correct output but diction is updating all the keys. Please provide insight into this behaviour as it is quite weird.