Original title: dictionary of dictionaries with same keys is changing all of the dictionaries within it [duplicate]
I am creating a dictionary of dictionaries that all have the same keys. in my real life code the keys are “part 1”:part1inventory, “part 2”:part2invetory……all the way to part 17. I need to increment/decrement the partinventories by deliveries/allocations. I am also saving that entire dictionary of 17 parts and their inventories as a dictionary with the week number on it. But I am finding in my code at the end that every week dictionary is just the last week part numbers. Here is an example structure of the code where the part inventories are all the same for each inner dictionary at the end of the 52 weeks. overallpartinventories={} partinventories={‘part a’:1,‘part b’:2} overallpartinventories[‘Week 1’]=[partinventories]
partinventories[‘part a’]+=1 # part a got a delivery of 1 partinventories[‘part b’]+=1 # part b got a delivery of 1 overallpartinventories[‘Week 2’]=partinventories overallpartinventories
what i expected was: {‘Week 1’: [{‘part a’: 1, ‘part b’: 2}], ‘Week 2’: {’