Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Iterate through dictionary keys and values

Access key-value pairs in a dictionary and return them as a list of tuples preserving insertion order.

Python practice8 minDictionaries & SetsBeginnerLast updated March 18, 2026

Problem statement

Given a dictionary, return a list containing (key, value) tuples for each entry in the dictionary. The order should reflect the dictionary's insertion order. The function should not print anything; it should return the list so that it can be tested.

Task

Implement a function that returns the dictionary's items as a list of (key, value) tuples in insertion order.

Examples

Simple dictionary

Input

iterate_dict({'a': 1, 'b': 2})

Output

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

The items are returned as a list of tuples in insertion order.

Input format

A single dictionary passed to iterate_dict(d).

Output format

A list of tuples [(key1, value1), (key2, value2), ...].

Constraints

Dictionary may be empty. Keys and values can be any types that can be stored in a dict.

Samples

Sample 1

Input

iterate_dict({1: 2, 3: 4})

Output

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

Numbers are returned as (key, value) tuples in the same order they were written.