So say that I have a dictionary with a default value of another dictionary
attributes = { 'first_name': None, 'last_name': None, 'calls': 0 } accounts = defaultdict(lambda: attributes)
The problem is that the default dictionary that I pass to defaultdict (attributes) is passed as a link. How to convey it as a value? Thus, changing values ββin one key does not change values ββin other keys
For instance -
accounts[1]['calls'] = accounts[1]['calls'] + 1 accounts[2]['calls'] = accounts[2]['calls'] + 1 print accounts[1]['calls'] # prints 2 print accounts[2]['calls'] # prints 2
I want each of them to print 1, since only once increased their corresponding values ββfor the "calls".
source share