Lesson guide
What this Python exercise practices
Pair Elements With Zip is a beginner practice lesson that focuses on loops, iteration, counters. It is designed to be solved in about 7 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
- 7 minutes
Practice path
Summary
Combine two sequences element-wise into pairs using zip.
Problem statement
Given two iterables a and b, return a list of tuples where each tuple contains the i-th element from a paired with the i-th element from b. If the iterables have different lengths, stop at the shorter one (behavior of zip).
Task
Use zip to pair corresponding elements from two iterables into a list of tuples.
Examples
Numbers pairing
Input
pair_elements([1,2], [3,4])
Output
[(1, 3), (2, 4)]
Explanation
Elements at matching positions are paired.
Input format
Two iterables: pair_elements(a, b)
Output format
A list of tuples: [(a0, b0), (a1, b1), ...]
Constraints
- Iterables may be of different lengths; pair only up to the shorter one. - Iterables may contain any types. - Do not assume inputs are lists (strings and other iterables should work).
Samples
Sample input 0
pair_elements([1,2,3], [4,5])
Sample output 0
[(1, 4), (2, 5)]
Explanation 0
Stops when the second iterable is exhausted.
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.