Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 13

Index and Value with Enumerate

Easy

6 minute session

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.

Code editor
Loading editor…

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.

02:26 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.