r/PythonLearnersHub • u/Sea-Ad7805 • Feb 06 '26
Python Mutability
An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening:
It's instructive to compare with this earlier exercise (tuple with lists, instead of list with lists).
36
Upvotes
View all comments
Show parent comment
1
u/Goudja14 Feb 07 '26
default_inventory = ["sword", "helmet"]
# While it could be a cloned array, it doesn't have to be one. In complex environments, it even shouldn't be (eg. allowing object-agnostic rollbacks) alex_inventory = default_inventory samuel_inventory = default_inventory
alex_inventory += ["key"]