← All Exercises

TypedDict for Structured Dicts

intermediatepython~15min

Background

TypedDict brings static typing to dictionaries, enabling IDE autocomplete and type checking.

Problem

Define a TypedDict for API response structure and validate field types with mypy.

Input

Dictionary with known structure

Output

Type-checked dictionary

Sample tests

Sample 1

Input: UserDict(name="Alice", age=30)
Expected: typed dict

Your solution

Learning objective

Learn structural typing and static analysis in Python