bterwijn

joined 7 months ago
[–] bterwijn@programming.dev 0 points 3 weeks ago (1 children)

Copying a list with a million elements every time you make a small change is not fun. Sure, you can optimize a bit behind the scenes, but that still gives a lot of overhead.

[–] bterwijn@programming.dev 0 points 3 weeks ago* (last edited 3 weeks ago) (2 children)

It's definitely not the same. Similarly for a class you can define the __add__ dunder method for a + b and separately the __iadd__ dunder method for a += b. The first creates a new object, the latter changes/mutates the existing object a. For immutable types it is the same though.

 

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

1
submitted 3 months ago* (last edited 3 months ago) by bterwijn@programming.dev to c/python@programming.dev
 

Data structures like Trie can in Python be easier understood and debugged after visualization using the memory_graph package.

A Trie is a tree of dictionaries and can be used for things like word completion.

[–] bterwijn@programming.dev 0 points 5 months ago

Nice one, see the "Solution" link for correct answer.

[–] bterwijn@programming.dev 0 points 5 months ago

Yes I understand your point, but I'm trying to reach out so people are aware and can use it in Python education. I feel it can really help beginners understand tricky concepts with ease, bit it's hard to reach a bigger audience these days. Sorry for the repetition, I'll guess I should cut back a bit.

 

Data structures become much easier to understand when students can see the structure of their data visualized using memory_graph. A data structure is no longer an abstract idea but concrete, clear and debuggable. Here’s a live demo of a Linear Linked List: https://memory-graph.com/#codeurl=https%3A%2F%2Fraw.githubusercontent.com%2Fbterwijn%2Fmemory_graph%2Frefs%2Fheads%2Fmain%2Fsrc%2Flinked_list_lin.py&breakpoints=27&continues=1&timestep=0.2&play=

[–] bterwijn@programming.dev 0 points 5 months ago

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

1
submitted 5 months ago* (last edited 5 months ago) by bterwijn@programming.dev to c/python@programming.dev
 

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:

 

Understanding and debugging Python data structures gets easier with memory_graph visualization. Here's a Multiway Tree example. A Multiway Tree is similar to a Binary Tree but has an arbitrary number of children making the tree less deep and more efficient.

 

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:

[–] bterwijn@programming.dev 0 points 6 months ago (1 children)

__add__ is called with + and __iadd__ is called with +=, and there is a difference: https://www.reddit.com/r/PythonLearning/comments/1nw08wu/right_mental_model_for_python_data/

 

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:

1
Python bitwise operators (programming.dev)
submitted 6 months ago* (last edited 6 months ago) by bterwijn@programming.dev to c/python@programming.dev
 

Teaching and learning Python bitwise operators gets much easier after showing the binary representations of integers using memory_graph: bitwise operators in Memory Graph Web Debugger

Understanding of the inverse ~ operator is helped by showing the two’s complement representation.

[–] bterwijn@programming.dev 0 points 6 months ago

C is incorrect,sorry. See the "Solution" link for the correct answer.

 

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:

 

Some struggle with recursion, but as package invocation_tree visualizes the Python call tree in real time, it gets easy to understand what is going on and to debug any remaining issues.

See this one-click Quick Sort demo in the Invocation Tree Web Debugger.

 

Better understand the Python Data Model or Data Structures by memory_graph visualization with just one click:

[–] bterwijn@programming.dev 0 points 7 months ago* (last edited 7 months ago)

Actually running the code? I got to the stage where only AI can help me understand anything ;-)

[–] bterwijn@programming.dev 0 points 7 months ago (2 children)

Thanks for your feedback, much appriciated.

I agree that an exercise14.rst would be nice, but to save time I've let the code speak for itself now together with the visualizaion. I'll probably revisit and better document the exercises later.

At the Explanation link I try to give a general explanation about Pyrhon mutability (and copy later on), I agree some readers might find it hard relate that to a specific exercise, but I don't want to write a specific explanation for each exercise.

[–] bterwijn@programming.dev 0 points 7 months ago

Thanks for report, should be fixed now.

[–] bterwijn@programming.dev 0 points 7 months ago (2 children)
[–] bterwijn@programming.dev 0 points 7 months ago* (last edited 7 months ago)

The "Solution" link gives the solution to the exercise, the "Explanation" link explains the Python data model concepts behind the exercise. If some parts are hard to understand let me know.

 

See the Solution and Explanation.

view more: next ›