Syncing account progress…

Back

Intermediate · 11 min

Enumerate and zip

Loop with positions and pair related collections safely.

Count while looping

enumerate() yields an index and an item. The start argument lets displayed positions begin at one.

tasks = ["Plan", "Build"]
for number, task in enumerate(tasks, start=1):
    print(number, task)

Output

1 Plan
2 Build

Pair matching items

zip() pairs values at the same position and stops when the shorter input ends.

names = ["Ada", "Mina"]
scores = [88, 94]
for name, score in zip(names, scores):
    print(f"{name}: {score}")

Output

Ada: 88
Mina: 94

Enumerate and zip

  1. Read both enumerate and zip examples before answering.
  2. Run the task, compare its exact output, and revise the code if needed.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Number a schedule

Use enumerate with start=1 to display each day as 1. Design and 2. Test.

Practice