#deepcopy — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #deepcopy, aggregated by home.social.
-
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:
- Solution: https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph_videos/refs/heads/main/exercises/exercise10.py&breakpoints=13&continues=1&play
- Explanation: https://github.com/bterwijn/memory_graph?tab=readme-ov-file#python-data-modelIf you think this could help Python students and educators, please boost.
-
This does bite people in Python, as it applies to lists and dicts in addition to Pandas or whatever that is.
list and dict have copy() methods, but they're shallow copies. If you have mutable objects in your list or dict, those can be changed by someone with a copy...
Use copy.deepcopy() to ensure you get a mutable object that no one else (barring evil intent...) has a handle to fiddle with its contents.