Data Structures .count() method

I’m curious about why we even bother implementing a count() method in any of the Data Structures in the books (Morepy or Javascript). Wouldn’t it be faster to just declare a property called count or length and increment that?

For educational purposes? So we learn how cumbersome it is to get that count? :slight_smile:
For what it’s worth, the data structures in the C book do have a count ‘property’.

Absolutely, and you should do that. Actually I think that’s an extra credit or I work on making it faster at some point. Let me know if I don’t.

Also, remember that you would never actually implement any of these data structures in JavaScript or Python. Those languages already have built-in hyperfast structures for most everything you need so doing this is purely an exercise. If I didn’t stress that enough in the book let me know.

I read through the book and I didn’t spot that particular extra credit, but perhaps the videos have it. I’ll keep you posted.

Otherwise it’s clear that this is just an exercise.

@zedshaw, if I have done the data structures in C, would you say I’m missing much if I skip that part in Learn More Python? I’m kind of eager to get to the parsing section…