0

I've been trying to solve this problem for hours in my discord bot, and have found something that makes me even more confused, can anyone tell me if I'm doing anything wrong? Data is a dictionary loaded from a data file, that contains keys of user id's, and the value of those user id's are dictionaries with info about the user. e.g. It doesn't seem like the dictionary is being updated...

data = {
    528904852321: {'pocket_money': 1000},
    085984902543: {'pocket_money': 1000},
}
print(data[robberid]['pocket_money']) # 1000
print(data[victimid]['pocket_money']) # 1000

amount = 50
print(amount) # 50

data[robberid]['pocket_money'] -= amount
data[victimid]['pocket_money'] += amount

print(data[robberid]['pocket_money']) # 1000
print(data[victimid]['pocket_money']) # 1000
FluffyFlounder
  • 140
  • 2
  • 8
  • Can you please share your code to this? – Dominik Apr 19 '21 at 08:41
  • This is definitely not reproducible, more code is needed to identify the problem – Ceres Apr 19 '21 at 14:19
  • I'm not sure stackoverflow would like my pasting 1k lines of code in here, however I have some more info about it; I have my dictionary 'data', and when I'm writing to a nested dictionary in data it seems to write to all of the dictionaries in the data, do you have any idea what it could be? @Ceres – FluffyFlounder Apr 19 '21 at 14:48
  • You don't need to provide all 1000 lines here, just the [MRE](https://stackoverflow.com/help/minimal-reproducible-example) – Ceres Apr 19 '21 at 15:59
  • nvm, got it fixed – FluffyFlounder Apr 19 '21 at 15:59
  • Great, you can post the solution here if it is relevant or delete the question if you want to. – Ceres Apr 19 '21 at 16:00
  • This guide: https://stackoverflow.com/questions/39474959/nested-dictionaries-copy-or-deepcopy fixed the issue. – FluffyFlounder Apr 19 '21 at 21:07

0 Answers0