From:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ 0013868196435255fcca20a1630446ea2dd434a7176e152000
Dict Default Iteration Key
>>> d = {' A ': 1, ' B ': 2, ' C ': 3}
>>> for key in D: ... Print Key
...
A
c
b
If you want to iterate between key and value at the same time, you can use the for K, V. in D.iteritems ()
>>> for K, v. in D.iteritems ():
Print K, V
A 1
C 3
B 2
Tuple iterations
>>> for X, y,z in [(1,1,11), (2, 4,6), (3, 9,5)]:
Print X,y,z
1 1 11
2 4 6
3 9 5
How can you tell if an object is an iterative object? The method is judged by the iterable type of the collections module:
>>> 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