Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 14

Pair Elements With Zip

Easy

7 minute session

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.

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.

03:40 AM

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