Challenge - 5 Problems
Enumerate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of enumerate with start index
What is the output of this Python code?
Python
items = ['apple', 'banana', 'cherry'] result = list(enumerate(items, start=1)) print(result)
Attempts:
2 left
๐ก Hint
Remember that enumerate can start counting from any number you choose.
โ Incorrect
The enumerate function returns pairs of (index, item). The start=1 argument makes the index start at 1 instead of 0.
โ Predict Output
intermediate2:00remaining
Using enumerate in a for loop
What will this code print?
Python
colors = ['red', 'green', 'blue'] for i, color in enumerate(colors): if i == 2: print(color)
Attempts:
2 left
๐ก Hint
The loop prints the color when the index is 2.
โ Incorrect
The enumerate function pairs each color with its index starting at 0. When i is 2, the color is 'blue'.
๐ง Conceptual
advanced2:00remaining
Behavior of enumerate on empty iterable
What is the result of converting enumerate([]) to a list?
Attempts:
2 left
๐ก Hint
Think about what happens when you enumerate over an empty list.
โ Incorrect
Enumerate over an empty iterable produces no items, so converting to list results in an empty list.
โ Predict Output
advanced2:00remaining
Output of enumerate with tuple unpacking
What does this code print?
Python
data = ['a', 'b', 'c'] for index, value in enumerate(data, 5): if index == 6: print(value)
Attempts:
2 left
๐ก Hint
The start index is 5, so the first item has index 5.
โ Incorrect
Enumerate starts counting at 5, so the second item has index 6, which is 'b'.
โ Predict Output
expert2:00remaining
Effect of modifying list during enumerate
What happens when you run this code?
Python
lst = [10, 20, 30] for i, val in enumerate(lst): if val == 20: lst.append(40) print(len(lst))
Attempts:
2 left
๐ก Hint
Think about how enumerate works with the list size changing during iteration.
โ Incorrect
Enumerate uses an iterator over the list. The list grows by one element during iteration, so the loop continues until the new element is processed. The final list length is 4.