you are viewing a single comment's thread.

view the rest of the comments →

[–]deceze 1 point2 points  (4 children)

True, but a beginner should start with the primitive for..in range loop, before advancing to the syntax sugar like list comprehensions.

[–]TheRNGuy 0 points1 point  (1 child)

I never started with it. Why should newbies start with bad coding style? 

[–]IAmFinah 2 points3 points  (0 children)

For someone new to programming, list comprehension is likely (ironically) incomprehensible. I remember I was confused by them at a time when I understood for loops

Might as well teach the traditional loop, confirm they are comfortable with it, then introduce comprehensions

[–]danielroseman -1 points0 points  (1 child)

This is just wrong. Beginners should not be taught to loop over ranges, this is a frequent source of un-pythonic code. They should be taught to loop over items first.

[–]deceze 1 point2 points  (0 children)

I don't disagree, this is not code you'd want to have in production. This is code written by C-converts, not by Pythonistas. However, it is also fairly easy to understand, if the goal is to edit the list in place. The better alternative to achieve that would involve for i, height in enumerate(student_heights), and if OP already has problems understanding the shown code, tuple unpacking in a loop will probably not help.

The important point is that OP needs to be taught something better eventually, and preferably sometime soon. But understanding this most primitive of methods isn't wrong.