Lesson guide
What this Python exercise practices
Index and Value with Enumerate is a beginner practice lesson that focuses on loops, iteration, counters. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Lists or strings
- Basic for loop syntax
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Related public exercises
Summary
Use enumerate to access both the index and value while iterating a sequence.
Problem statement
Given a list, return a new list containing tuples where each tuple holds the index and the corresponding value from the input list. Use Python's enumerate to access both index and value while iterating.
Task
Learn to produce a list of (index, value) pairs from an input sequence using enumerate.
Examples
Basic example
Input
enumerate_pairs(['a', 'b', 'c'])
Output
[(0, 'a'), (1, 'b'), (2, 'c')]
Explanation
Each element is paired with its index in a tuple.
Input format
A single list argument: enumerate_pairs(lst)
Output format
A list of tuples: [(index0, value0), (index1, value1), ...]
Constraints
- The input may be empty. - Elements may be of any type. - Preserve order and use zero-based indexing.
Samples
Sample input 0
enumerate_pairs([10, 20])
Sample output 0
[(0, 10), (1, 20)]
Explanation 0
Two elements become two (index, value) tuples.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.