Answer key · 12 questions

Python enumerate and zip Exercises With Answers

All 12 questions for Python enumerate and zip in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python enumerate and zip, with the exact answer and a short explanation for every question.

The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.

01 · Multiple choice

What does enumerate produce on each pass?

  1. An index and an itemcorrect
  2. Only the index
  3. A copy of the list
  4. Only the item

Answer: An index and an item

Why: enumerate yields a pair containing the position and the value.

02 · Multiple choice

What does this code print?

print(list(enumerate(["a", "b"], start=1)))
  1. [(1, 'a'), (2, 'b')]correct
  2. [(0, 'a'), (1, 'b')]
  3. 1 a 2 b
  4. ['a', 'b']

Answer: [(1, 'a'), (2, 'b')]

Why: start=1 begins the numbering at one, and list() shows each pair.

03 · Multiple choice

What does zip do when the lists have different lengths?

  1. Stops at the shortest listcorrect
  2. Raises ValueError
  3. Pads with None
  4. Repeats the shorter list

Answer: Stops at the shortest list

Why: zip stops as soon as one input is exhausted.

04 · Multiple choice

Which loop prints 1 Ada and 2 Grace?

  1. for n, name in names:
  2. for n in enumerate(names):
  3. for n, name in enumerate(names, start=1):correct
  4. for n, name in zip(names, start=1):

Answer: for n, name in enumerate(names, start=1):

Why: enumerate takes the iterable first and start as a keyword argument.

05 · Fill in the blank

Complete the loop so each item gets an index.

items = ["a", "b"]
for i, item in ____(items):
    print(i, item)

Answer: enumerate

Why: enumerate yields the index and item together.

06 · Fill in the blank

Complete the argument that starts numbering at one.

for n, item in enumerate(["a", "b"], ____=1):
    print(n, item)

Answer: start

Why: The keyword argument is start.

07 · Fill in the blank

Complete the function that pairs two lists.

names = ["Ada", "Grace"]
scores = [92, 88]
pairs = list(____(names, scores))

Answer: zip

Why: zip walks two iterables in parallel.

08 · Fill in the blank

Complete the call that produces (0, 'a') first.

print(next(____(["a"])))

Answer: enumerate

Why: next() asks enumerate for its first pair.

09 · Predict output

What does the program output?

print(list(enumerate(["x", "y"])))

Answer: [(0, 'x'), (1, 'y')]

Why: The default start is zero, and list() shows the pairs.

10 · Predict output

What appears on the screen?

print(list(zip([1, 2], ["a"])))

Answer: [(1, 'a')]

Why: zip stops when the shorter input runs out, so only one pair remains.

11 · Predict output

What is printed?

print([i for i, _ in enumerate("abc", start=2)])

Answer: [2, 3, 4]

Why: The indexes are 2, 3, and 4 even though the characters are not used.

12 · Predict output

What is the output?

print(dict(zip(["a", "b"], [1, 2])))

Answer: {'a': 1, 'b': 2}

Why: zip creates pairs, and dict turns each pair into a key and value.

Try the questions first

Open the practice page for Python enumerate and zip and answer the same 12 questions with instant feedback.

Practice this lesson