promptdojo_

enumerate and zip — the loops AI writes when it's not lazy — step 6 of 9

AI wrote the C-style version with range(len(...)) and items[i], and slipped an off-by-one on line 3: range(len(items) + 1) runs one iteration past the end of the list, and line 4 raises IndexError on the last pass.

Replace lines 3-4 with a single for loop using enumerate so the output is:

0: apple
1: bread
2: steak
The break is on lines 3, 4 — but read the whole snippet first.

full-screen editor opens — close anytime to keep reading.