Hacker News new | ask | show | jobs
by kerpal 4522 days ago
Thanks for this write up. I didn't know about enumerate. I never thought of swapping variables as in example 4 either.

I noticed one small mistake in section 9:

  d[keys] = values[i] 
Should be:

  d[key] = values[i]
1 comments

For a good few months I was doing

    for i in range(len(input_list)):
        v = input_list[i]
        ...do something with v and i...
enumerate is much nicer!

    for i, v in enumerate(input_list):
        ...