Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Reconstruct a list from value-count tuples

Build a flattened list by repeating values according to provided counts.

Python practice25 minLists & TuplesAdvancedLast updated March 17, 2026

Problem statement

Write a function reconstruct(pairs) that takes a list of tuples pairs where each tuple is (value, count). Return a single list containing each value repeated count times, preserving the order of tuples. You may assume count is a non-negative integer. If pairs is empty, return an empty list.

Task

Given a list of (value, count) tuples, return a list where each value appears count times in order.

Examples

Simple numeric reconstruction

Input

[(1, 3), (2, 1)]

Output

[1, 1, 1, 2]

1 repeated 3 times, then 2 repeated once.

Input format

A single argument: a list of (value, count) tuples. count is a non-negative integer.

Output format

Return a list with values repeated according to their counts.

Constraints

Do not import external libraries. Counts are non-negative integers; handle zero by producing no occurrences of that value. Maintain the input order.

Samples

Sample 1

Input

[('a', 2), ('b', 0), ('a', 1)]

Output

['a', 'a', 'a']

First 'a' twice, then 'b' zero times (skipped), then 'a' once more.