Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

dict.items

Exposes a dynamic view of key and value pairs in insertion order.

Version: Python 3.14; repository image, production runtime not attested

Syntax

m.items()

Exposes a dynamic view of key and value pairs in insertion order.

Keeping the view does not freeze its contents. A later insertion appears when the view is iterated.

The view exposes key-value pairs in dictionary insertion order. It reads current bindings, so inserting b after creating the view still appears when list materializes the pairs. The resulting list then has independent outer storage.

d = {"x": 1}
pairs = d.items()
d["x"] = 2
assert list(pairs) == [("x", 2)]

Examples

m = {"a": 3}
view = m.items()
m["b"] = 8
print(list(view))

Result

[('a', 3), ('b', 8)]

The view exposes key-value pairs in dictionary insertion order. It reads current bindings, so inserting b after creating the view still appears when list materializes the pairs. The resulting list then has independent outer storage.

Sources