Items method
The Python dictionary items() method returns a dynamic view of the dictionary’s key-value pairs.
The Quick Python Book, Fourth Edition
The dictionary items method returns the dictionary's key-value pairs as iterable tuple-like items.
- How it is used
- Supplies key–value pairs for dictionary iteration and for sorting word counts by frequency.
- How deep it goes
- Defines the returned view, shows tuple pairs and list conversion, and applies them in a sorting workflow without examining implementation internals.
- Examples
- Shows translation pairs and a word-frequency program that prints the five most and least common words.
- What you can do after
- Apply it via Python’s `dict.items()` to obtain key–value pairs and sort a list of them by value.
Read how The Quick Python Book, Fourth Edition explains items method →
Python Workout: 50 ten-minute exercises
dict.items is the dictionary method that returns an iterator over the dictionary's key-value pairs.
- How it is used
- Uses dictionary iteration to process key-value pairs for formatting, transformation, and generated attributes.
- How deep it goes
- Explains the returned iterator, pair unpacking, and comprehensions, stopping short of implementation internals.
- Examples
- Demonstrates XML-like attribute generation and dictionary value transformation.
- What you can do after
- Apply it via comprehensions to build formatted strings or new dictionaries from existing key-value pairs.
Read how Python Workout: 50 ten-minute exercises explains items method →
Related concepts
- iteratorproduces · An iterator is an object or abstraction that provides successive values from a sequence or data source through a traversal protocol.
- tupleproduces · A tuple is a finite, ordered collection of elements treated as a single composite value or record.
- name-value pairproduces · A name-value pair is a data association in which an identifying name or key corresponds to a value.
- Mapuses · A map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- dictionary view objectproduces · A dictionary view object is a dynamic Python object exposing a dictionary’s keys, values, or key-value pairs and reflecting subsequent dictionary changes.
- comprehensionuses · A comprehension is a language construct that creates a collection by iterating over one or more sources, optionally filtering elements and transforming them.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

