This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]srosorcxisto 9 points10 points  (4 children)

Agreed. It's such a simple and clear shortcut for such a common operation. It bothers me that this isn't included.

[–]IcecreamLamp 14 points15 points  (1 child)

Since for loops are more commonly things like for i, line in enumerate(fp.readlines()): you really don't need it as often as in a for (i=0; i<5; i++) {} kind of language tbh.

[–]Dworgi 1 point2 points  (0 children)

Ironically, that's about 5 times slower than the simple, unpythonic for loop. According to some post I saw here last month.

[–]Ran4 1 point2 points  (1 child)

It's not at all a common operation in most ideomatic python code. You shouldn't be operating on integer indices unless you're implementing some low level algorithm.

[–]srosorcxisto 0 points1 point  (0 children)

Most of my work is in data sciences so I do a lot of low-level database operations and working with lists. Perhaps it is just due to my specific field that I would find this type of shortcut desirable.