I am trying to copy a dictionary that has sets as values.
dic = {0: set([1]), 1: set([0, 2]), 2: set([1, 3]), 3: set([2, 4]), 4: set([3])}
dic1 = dic.copy()
dic1[0].update(dic[1])
print dic
print dic1
and I am getting
{0: set([0, 1, 2]), 1: set([0, 2]), 2: set([1, 3]), 3: set([2, 4]), 4: set([3])}
{0: set([0, 1, 2]), 1: set([0, 2]), 2: set([1, 3]), 3: set([2, 4]), 4: set([3])}
so basically they are now the same thing. I have tried doing dictionary comprehension and doing .copy() and nothing! How can I make it so that the original dictionary remains untouched?
I went to python tutor and basically, the keys are in dic1 but the values are linked to the ones in dic. How can I make it so they have independent values?