When iterating directly over a dictionary e.g., for k, v in some_dict:
or {k: v for k, v in some_dict}
, Python iterates
over the dictionary’s keys by default. If the intention is to access both the key and the value, omitting .items()
leads to unexpected
behavior. In such cases, the k
variable would receive the key, and the v
variable would attempt to unpack the key itself,
which can lead to errors or subtle bugs if the key is iterable, like a string
. For example, if a key is a string
like
"hi"
, k
would be 'h'
and v
would be 'i'
.