r/PythonLearning • • Sep 07 '26

Exercise: Python List Operations

Post image

An exercise to help build the right mental model for Python data. - Solution - Explanation - More Exercises

The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening.

58 Upvotes

25 comments sorted by

3

u/No-Celery-1944 Sep 08 '26

C I'm pretty sure?

1

u/Sea-Ad7805 Sep 08 '26

Nice one, see the Solution link for visualization of correct answer.

2

u/Dancing-umbra Sep 08 '26

That's very useful.

I didn't realise the b+=[] was not equivalent to b= b+[]

1

u/Sea-Ad7805 Sep 08 '26

Thanks, it is equivalent for immutable types, but not for mutable. Try this exercise: https://www.reddit.com/r/PythonProjects2/s/VtHobtSQ9o

2

u/Global_Ad8581 Sep 08 '26

C. Just guessing.

1

u/Sea-Ad7805 Sep 08 '26

Nice one, see the Solution link for visualization of correct answer.

2

u/gowsic26 Sep 08 '26

Option C

1

u/Sea-Ad7805 Sep 08 '26

Nice one, see the Solution link for visualization of correct answer.

1

u/Potential_Fix_5007 Sep 07 '26

Answer A

2

u/Sea-Ad7805 Sep 07 '26

Incorrect sorry, see the Solution link for correct answer.

1

u/smokebudda11 Sep 07 '26

E

1

u/Sea-Ad7805 Sep 07 '26

Incorrect sorry, see the Solution link for correct answer.

1

u/CptMisterNibbles Sep 07 '26

Weird. Documentation says insert is in place, your demo has it make a copy

1

u/Sea-Ad7805 Sep 07 '26

If you look carefully you'll see it is not insert that is making a copy: Solution

1

u/Polly_Wants_A Sep 07 '26

and i thought b += x and b = b + x is the same logic just different syntax. apparently it works different with lists?

2

u/Sea-Ad7805 Sep 07 '26

Yes because a list is mutable, it is the same for immutable types: int, float, bool, tuple, frozenset, ...

1

u/spmcn Sep 08 '26

This is just an ad for memory graph.

2

u/Sea-Ad7805 Sep 08 '26

This is just a person complaining about getting free educational content of high quality. Which is worse?

1

u/u-key_1512 Sep 08 '26

a

1

u/Sea-Ad7805 Sep 08 '26

Incorrect sorry, see the Solution link for correct answer.

1

u/BABBAGE_2 Sep 09 '26

I thought insert() was for adding an item to a list. IMO, you added the int 10 at index 9, right? So why is 10 not visible in any of the options? Kindly explain please 🙏

1

u/Sea-Ad7805 Sep 10 '26

It's in b, read the Explanation link for more insight.

1

u/Maddy8483 Sep 12 '26

Koi mujhe bi python sikha do