#mutability — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #mutability, 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/exercise7.py&play
- Explanation: https://github.com/bterwijn/memory_graph?tab=readme-ov-file#python-data-model -
As much as I value data integrity, I also appreciate data mutability. I’ve never understood the crowd that insists there's only one best solution.
-
Oh, and sets too.
Example with shallow list copy and an embedded mutable object (another list):
>>> a = [1, 2, [3, 4]]
>>> b = a.copy()>>> b
[1, 2, [3, 4]]
>>> b[0] = 5
>>> b
[5, 2, [3, 4]]>>> a
[1, 2, [3, 4]]>>> b[2][0] = 8
>>> a
[1, 2, [8, 4]]
>>> b
[5, 2, [8, 4]]