I have a list with certain value. I need to assign the data in the list as initial values to all keys in a dictionary. I want that only data of the variable should be assigned to the key and not the variable. The code I have return changes the variable value thereby changing it for every key. How to copy only data from a variable to assign to a key. I understand that It the code has created a reference of same variable. I want to know how to assign data from the variable without any reference
#Initialize Dictionary with values of List
my_list = [0] * 20
my_dict = {"A_key":my_list ,"B_key":my_list,"C_key":my_list}
#Edit Dictionary
my_dict["A_key"][4] = "Changed_Data"
#Print values
print(my_dict)
print(my_list)
Actual Result
{'B_key': [0, 0, 0, 0, 'Changed_Data', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'A_key': [0, 0, 0, 0, 'Changed_Data', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'C_key': [0, 0, 0, 0, 'Changed_Data', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}
[0, 0, 0, 0, 'Changed_Data', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Expected Result
{'B_key': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'A_key': [0, 0, 0, 0, 'Changed_Data', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'C_key': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]