Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Create consecutive pairs with zip

Use zip to build consecutive pairs from a sequence. Practice slicing and pairing adjacent elements efficiently.

Python practice8 minModules & Standard LibraryBeginnerLast updated March 23, 2026

Problem statement

Given a list of elements, return a list of consecutive pairs (as 2-tuples). Each pair should contain element i and element i+1 for all valid i. If the input list has fewer than two elements, return an empty list. Use Python's built-in zip and slicing to create the pairs efficiently.

Task

Write a function that returns a list of consecutive pairs (tuples) from an input list using zip.

Examples

Simple numeric list

Input

consecutive_pairs([10, 20, 30])

Output

[(10, 20), (20, 30)]

Pairs are (10,20) and (20,30).

Input format

A single list of values passed into consecutive_pairs(lst).

Output format

A list of 2-tuples representing adjacent element pairs.

Constraints

Do not modify the original list. The input list may contain any Python objects (numbers, strings, etc.). Time complexity should be O(n).

Samples

Sample 1

Input

consecutive_pairs(['a', 'b', 'c'])

Output

[('a', 'b'), ('b', 'c')]

Consecutive string pairs from the list.