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
Uses dictionary items to iterate over key-value pairs and prepare word counts for sorting.
How deep it goes
Explains the dynamic view, list conversion, membership tests, conditional set operations, and sorting by tuple value.
Examples
Demonstrates English-to-French dictionary entries and a word-frequency exercise that selects the most and least common words.
What you can do after
Apply it via Python dictionaries to iterate over entries and sort word-frequency pairs.

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 →

Also covered in

What to know first

Related concepts

Questions about items method

What is items method?

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

Which Manning books explain items method?

The Quick Python Book, Fourth Edition and Python Workout: 50 ten-minute exercises.

What should I know before learning items method?

Manning books that teach items method usually introduce Map, loop, comprehension and floating-point arithmetic first.

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.