Python provides several iteration API over collections(specially dictionary). In python2, there was dict.iteritems() for key/value iteration. Starting from python3, iteritems was replaced by items()i (see SO). and there is also enumerate which works with all collections not just dict.

dict.items() Link to heading

Defined in pep, items() returns key/value iterator over dict. Although, items behaves the same in python2 and 3. but there is a difference in return type. In python2, items() returns list but in python3, it returns an iterator.

d = {"a":1, "b":2}

items_ = d.items()
print((items_))
print(type(items_))

for k, v in  items_:
    print(k,v)

prints

dict_items([('a', 1), ('b', 2)])
<class 'dict_items'>
a 1
b 2

enumerate Link to heading

Define in pep, enumerate works with iterable collections to provide iterator over index, value (in case of dict, it would be index, key).

d = {"a":1, "b":2}
enumerate_ = enumerate(d)
print(enumerate_)
print(type(enumerate_))

for (id, v) in enumerate_:
    print(id, v)

prints

<enumerate object at 0x7f79a5f67b40>
<class 'enumerate'>
0 a
1 b