dict.values() vs dict.items()
dict.values() and dict.items() are both Python Dictionary Methods APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. dict.values(): Returns a view object of all values in the dictionary. Its syntax is dict.values(), and it returns values view dict.items(): Returns a view object of all (key, value) pairs as tuples. Its syntax is dict.items(), and it returns items view Example of dict.values(): d = {"a": 1, "b": 2}
list(d.values()) # [1, 2]. Example of dict.items(): d = {"a": 1, "b": 2}
list(d.items()) # [("a", 1), ("b", 2)]. Read the full references for dict.values() and dict.items() to see parameters, edge cases, and example code side by side. Other Dictionary Methods APIs worth comparing: dict.get(), dict.keys(), dict.update(), dict.pop(), dict.popitem(), dict.setdefault(). Both belong to the Dictionary Methods category in the Python Reference documentation.