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.
⌘↵ runs the editor.read, then continue.
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.
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.