CKTIS / Python
dict.keys
Exposes a live, set-like view of dictionary keys.
Version: Python 3.14; repository image, production runtime not attested
Syntax
m.keys()Exposes a live, set-like view of dictionary keys.
The view reflects subsequent insertions; set operations produce separate result sets.
The keys view reflects later insertion of b, which appears in insertion order when materialized. Its intersection with a set produces a new set of common keys, in this case only a. Changing that set does not alter the dictionary.
d = {"x": 1}
k = d.keys()
old = k | {"y"}
d["z"] = 2
assert "z" in k and "z" not in old
Examples
m = {"a": 3}
view = m.keys()
m["b"] = 8
print(list(view))
print(sorted(view & {"a", "c"}))
Result
['a', 'b'] ['a']
The keys view reflects later insertion of b, which appears in insertion order when materialized. Its intersection with a set produces a new set of common keys, in this case only a. Changing that set does not alter the dictionary.