I have a question about some python dictionary behavior i haven't seen yet. (i am using python3.6)
I have a dictionary first_dict containing two keys "kk" and "aa", both linked to a list. Then i make a new dict namly second_dict. Now comes the strange thing, whenever i make a variable like fractions and edit this value, it automatically updates my dictionary. So i assume python automatically makes a connection between dictionary derived variables.
def main():
first_dict = {"kk": [0.0, 1.0], "aa": [0.5, 1.0]}
second_dict = first_dict
fractions = second_dict["kk"]
fractions.pop(0) #del fractions[0] gives same result
print(first_dict) #{'kk': [1.0], 'aa': [0.5, 1.0]}
print(second_dict) #{'kk': [1.0], 'aa': [0.5, 1.0]}
if __name__ == "__main__":
main()
My question is can i remove these connections, i found a solution to remove the connection between fractions and my second_dict by using:
fractions = list(second_dict["kk"])
however i could not find a solution to remove the connection between first_dict and second_dict. So i want to change second_dict and leave the first_dict unchanged.