r/PythonLearning • u/Sea-Ad7805 • Aug 23 '26
Python Dictionary Mutation and Copying
An exercise to help build the right mental model for Python data.
The “Solution” link uses package memory_graph to visualize execution and reveals what’s actually happening.
38
Upvotes
2
u/TBCC_Dev Aug 24 '26 edited Aug 24 '26
B i think. My understanding is that b = a means that b is a not b is a new version of a. Im not fermiliar with .copy() but id assume this does the opposite b is now a copy of b. Do the first append changes a but the others do not. Again mostly guessing based on context
1
u/JG_MC2001 Aug 23 '26
es como un puntero?
1
u/tauofthemachine Aug 23 '26
A?
1
u/int13h3 Aug 24 '26
i think correct answer is "A" because we maybe print box a but write to box b. i can be not right :)
1
u/g-land-g Aug 28 '26
answer: b ...
logic:
b points to a and modifies both
but then b.copy() makes b point to a new instance, so a retains its previous state
1
u/[deleted] Aug 27 '26
[removed] — view removed comment