I am new to programming so hopefully the answer will be easy. I was trying to set a dictionary equal to another dictionary, but whenever the second dictionary changed values, so did the first one. (without me telling it to.) For example
dictA = {'a':1}
dictB = {}
for x in range (1,5):
dictB = dictA
print "dictB is ",
print dictB
dictA['a'] += 1
print "dictA is ",
print dictA
print "and dictB is ",
print dictB
Returns:
dictB is {'a': 1}
dictA is {'a': 2}
and dictB is {'a': 2}
dictB is {'a': 2}
dictA is {'a': 3}
and dictB is {'a': 3}
dictB is {'a': 3}
dictA is {'a': 4}
and dictB is {'a': 4}
dictB is {'a': 4}
dictA is {'a': 5}
and dictB is {'a': 5}
Is there a way to maintain the value of dictB until the end of the loop? Thanks