0

I am trying to use a copy of the decision_root dict, but my function handle_research, after return, changes the values of decision_root.

NOTE: I am not referring to decision_root anywhere in handle_research function.

while((len(decision_root['researches']))>0):
    research = decision_root['researches'][0].copy()
    decision_root['researches'].pop(0)
    research_chance = handle_research(research.copy(), decision_root.copy())
Stathis
  • 1
  • 1
  • 2
    The values in `decision_root` are mutable. `dict.copy()` returns a shallow copy, not a deep copy, so the values would be aliases in both copies, and mutating the value of one in-place would change the view through the alias to the same value in the other. Short answer: Use `copy.deepcopy(decision_root)`. – ShadowRanger Jan 11 '21 at 18:48
  • Thank you very much. I appreciate your help in this matter. – Stathis Jan 11 '21 at 18:52

0 Answers0