Traversing data, which we call iterative
For traversing data in Python, we typically use for...in
>>> d = {' A ': 1, ' B ': 2, ' C ': 3}
>>> for key in D: ... Print (key) ...
A
c
b
This allows you to simply iterate through the data. By default, if the Dict (dictionary structure) sequence of iterations is not necessarily, and is the iteration of the key, we use for value in D.values () if we want to iterate over the value. The way if key and value are to be traversed using for key,value in D.items ()
Note that strings are also objects that can be iterated to determine whether an object can be iterated
We use the Collections module's iterable type to determine whether we can iterate
>>> from collections import iterable
>>> isinstance (' abc ', iterable) # str can iterate
True
>>> isinstance ([1,2,3], iterable) # list can iterate
True
>>> isinstance (123, iterable) # integers can be iterated
False