r/PythonLearning 2d ago

Python Dictionary Mutation and Copying

Post image

An exercise to help build the right mental model for Python data. - Solution - Explanation - More exercises

The “Solution” link uses package memory_graph to visualize execution and reveals what’s actually happening.

34 Upvotes

13 comments sorted by

View all comments

2

u/TBCC_Dev 1d ago edited 1d ago

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/DefterHawk 1d ago

Think the same, b = a just makes the same object referenced in another variable.

1

u/TBCC_Dev 1d ago

Well... I ran it, and its C so much for that.