Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Even when programming in python, half the time I find myself switching to a simple loop over an index because I realize I need the index.

If you need to iterate over an iterable xs and discover you need the index as well, in Python you shouldn't switch to a loop over the index, you should switch from:

  for x in xs:
    ...
to:

  for idx, x in enumerate(xs):
    ...


Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: