by travisjungroth · 6y ago · 0 comments
The example in the readme isn't idiomatic Python. It would be better to use enumerate.
Yes, enumerate is better, but I want to teach concepts one at a time and I want students to understand what's going on in code. Before teaching `for a, b in c` I want to teach `a, b = c`. And to motivate doing that I want to teach `return a, b`. At this point in the course they're only just starting to learn about lists - they haven't seen tuples and they've never defined a function. So it's not time yet.
Besides, it's important that students are intimately familiar with how to index a list a which indices are valid.
To continue to be nit picky with that example, the range function produces an iterable object, which is different from a list.
It makes teaching harder. You really have to work to come up with great examples. But it makes learning easier and there's less correcting to do later.
A teacher is in a position of authoritative trust. As a student, after I learn an example is flawed, I often wonder if I’m just missing some context because I trust the teacher to have gotten it right. In a setting where communication is already established (e.g., a class room) this can be cleared up quickly with a question. In other settings (e.g., reading a text), it can leave me wondering until I reach a much higher level of competence.
But you may be surprised how many list-like operations `range` supports. Subscripting, `len`, `in`, `.count`, `.index`. It might as well be a tuple.
And if you want to nitpick more, range isn't a function.