32

An exercise to help build the right mental model for Python data.

The โ€œSolutionโ€ link visualizes execution and reveals whatโ€™s actually happening using ๐—บ๐—ฒ๐—บ๐—ผ๐—ฟ๐˜†_๐—ด๐—ฟ๐—ฎ๐—ฝ๐—ต: https://github.com/bterwijn/memory_graph

you are viewing a single comment's thread
view the rest of the comments
[-] m532@lemmygrad.ml 1 points 1 week ago

Let's look at the suspects.

b.append(), you add to the existing list. This mutates the current list. You can not be the culprit.

b = b + [], you join up lists, making a new list in the process, that then gets stored in variable b, without changing the original list that's still stored in variable a. You are not the culprit either.

No, the culprit must be someone that ambiguously looks both like a mutation and an instantiation.

Isn't that right, b += []? Because the culprit... IS YOU!

this post was submitted on 01 Apr 2026
32 points (86.4% liked)

Python

7863 readers
2 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS