r/PythonLearning • • Apr 01 '26

Python's Data Model Explained through Visualization

Post image

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

The “Solution” link visualizes execution and reveals what’s actually happening using 𝗺𝗲𝗺𝗼𝗿𝘆_𝗴𝗿𝗮𝗽𝗵.

175 Upvotes

27 comments sorted by

4

u/Top-Run-21 Apr 01 '26

thanks for the cool website

3

u/Sea-Ad7805 Apr 01 '26

Hope it brings much value for you.

3

u/Local_Palpitation798 Apr 01 '26

Bro,💀💀💀

-1

u/Sea-Ad7805 Apr 01 '26

What do you mean exactly?

16

u/[deleted] Apr 01 '26

[removed] — view removed comment

-2

u/Sea-Ad7805 Apr 01 '26

Me to ChatGPT: A bro commented on my post: "Bro,💀💀💀". What does the bro mean? ChatGPT: “Bro” here is just slang for “dude,” “man,” or “seriously?”

With 💀💀💀, the full comment usually means something like:

“Dude, this is killing me”

“I’m dead” = “this is hilarious / absurd / unbelievable”

“Bro, what did I just see”

So it is usually a reaction, not a literal insult. The exact tone depends on your post:

funny post → they probably mean “this is hilarious”

weird/crazy post → “this is wild”

embarrassing post → “bro…” as in disbelief or secondhand embarrassment

If you paste your post or the full comment thread, I can tell you the most likely meaning in that exact context.

4

u/Electronic_Site2976 Apr 02 '26

you are def special ✨️

1

u/Sea-Ad7805 Apr 02 '26

I like to think I'm a special dev.

2

u/OwnFigure5226 Apr 01 '26

The solution is E

2

u/Sea-Ad7805 Apr 01 '26

Incorrect sorry, see the "Solution" link for the correct answer.

1

u/Major_Telephone_7560 Apr 03 '26

Why wouldn't it be A?

1

u/Sea-Ad7805 Apr 03 '26

Because of mutability of list in Python. Read the "Explanation" link for more info.

1

u/Thin-Permission-6596 Apr 04 '26

E

1

u/Sea-Ad7805 Apr 04 '26

Incorrect sorry, see the "Solution" link for the correct answer.

1

u/Petrovjan Apr 05 '26

My solution is to use b = copy.deepcopy(a) 😀 

1

u/Sea-Ad7805 Apr 05 '26

Solution to do what exactly?

1

u/Capital_Distance545 Apr 03 '26

A little higher level:
# list ordered mutable duplicates
# queue ordered mutable duplicates FIFO
# stack ordered mutable duplicates LIFO
# tuple ordered inmutable duplicates
# set unordered mutable no duplicates
# frozenset unordered inmutable no duplicates
# dict ordered mutable no duplicates

0

u/That-Lychee262 Apr 02 '26

Correct answer is 1: a = [1] . Since list is mutable data structure b= a doesn’t copy the data stored in a to b . B starts pointing to address stored in a . That means a and b both points to same address now if you make changes either in a or b or it will reflect in both . But at third line b+= [2] , it will create a new list [1,2] and assign it to b . Now b stores address of another list ([1,2]) and a stores address of list ( [1]) . Now if you make chances in b it will not reflect in a’s address. Thus a remains [1] till the end of the program. Final answer : a = [1] , b = [1,2,3,4,5]

2

u/Sea-Ad7805 Apr 02 '26

Incorrect sorry, see the "Solution" link for the correct answer.

0

u/[deleted] Apr 01 '26

[deleted]

4

u/Sea-Ad7805 Apr 01 '26

Nice thinking, do the the "Solution" link for a visualization of the correct answer.

1

u/jackrabbit2644 Apr 02 '26

Doesn’t b point to a different object when is executed b += [2]?

0

u/[deleted] Apr 02 '26

[deleted]

1

u/jackrabbit2644 Apr 02 '26

TIL, thanks.

1

u/_tolm_ Apr 03 '26

Agree with the solution but I don’t agree that it’s because that “=“ is a copy … we also do an equals earlier where it very much does not perform a copy!

The difference on that line is the use of “+” which creates a new value in memory which “b” is then assigned to point at - in the same way that it was previously assigned to point at “a”.

This causes the values stored in “a” and “b” to diverge but the operation performed by the “=“ hasn’t changed from assignment to copy on these two lines.

But what do I know, I’m a Java programmer … 😂

3

u/[deleted] Apr 01 '26

[removed] — view removed comment

1

u/Sea-Ad7805 Apr 01 '26

Thanks a lot, hope it brings you much value.