Transforming and Combining Data · practice
Count with enumerate()
The previous lesson unpacked related values supplied by a
We could create the position ourselves with a counter:
This works, but the counter is another
Python’s enumerate() produces the position and value together:
Each loop item from enumerate is a two-item tuple. The unpacking from the previous lesson gives those items the names number and prompt.
Index or display number?
By default, enumerate(prompts) starts at 0, matching Python 1:
Choose the start based on what the number means. Use zero for an actual list
Which loop gives you separate number and prompt values, starting number at 1?
Build numbered prompt lines
Complete a pure
Task
Complete number_prompts.
with enumerate(prompt_list, start=start).Append
in the form number. prompt.Return the new
. Keep
start=1as the default.
Do not change prompt_list.