I am trying to add an element to a set within a dictionary in Python, but when I use mydictionary[index].update([newelement])
, all the dictionary is being updated with the newelement. Here goes the python console commands and outputs to demonstrate what I am saying:
>>> graph=dict.fromkeys(range(10),set([]))
>>> graph
{0: set([]), 1: set([]), 2: set([]), 3: set([]), 4: set([]), 5: set([]), 6: set([]), 7: set([]), 8: set([]), 9: set([])}
>>> graph[0].update([1])
>>> graph
{0: set([1]), 1: set([1]), 2: set([1]), 3: set([1]), 4: set([1]), 5: set([1]), 6: set([1]), 7: set([1]), 8: set([1]), 9: set([1])}
So why isn't updating only the entry for graph[0]
?
I really tried to find a topic with this question specifically, but I didn't find one.
Obs: The parenthesis with numbers are the commands in python console.