Spyke

Replies

python

Comment on

Data Structures Made Clear

Reply in thread

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.

python

Comment on

Python Mutability

Reply in thread

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.

python

Comment on

Memory Graph Web Debugger

Reply in thread

Glad you like it. Sketching by hand should remain standard practice, but for beginners that might be difficult. First they need to learn the right mental model to think about Python data, and I hope memory_graph can help with that.

python

Comment on

Python Mutability

Reply in thread

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 to relate that to a specific exercise, but I don't want to write a specific explanation for each exercise.

python

Comment on

Adding objects to set or dictionary: equality and hashing

Reply in thread

Sure, but a lot of people incorrectly think the __eq__ and __hash__ are defined based on value not identity, as they are for many other types say float, str, or tuple. But for a class the default __eq__ method is x is y instead of x == y and also __hash__ is based on identity.

Others assume that if you don't define __hash__ for a class, that it doesn't exists (like for list, set, or dict) so that a "TypeError: unhashable type: 'Value'" exception is raised.

I thought it was an interesting exercise to share, but maybe too simple for this audience, or people are just not aware of the basic steps that happen when adding and searching values in a set/dict. Try the same with type int:

v1 = 1001
v2 = 1002
myset = {v1}
print(v1 in myset, end=' ')
v2 = 1001
print(v2 in myset, end=' ')
v1 = 1002
print(v1 in myset, end=' ')

and you see a different output. To do the same with the Value class add methods:

def __eq__(self, other):
    return self.value == other.value

def __hash__(self):
    return hash(self.value)
python

Comment on

Memory Graph Web Debugger

Reply in thread

Thanks for adding. The link I posted should give people a quick animation to directly see what is possible instead of having to read through things first. That GitHub repo link is also on hat page. But you are right that some would probably want to start with the repo, thanks for feedback.