liveBook · Manning

Items method

The Python dictionary items() method returns a dynamic view of the dictionary’s key-value pairs.

How 2 Manning books explain it

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

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.