In [1]:
# iteration is typically done using for/in and indented block
a = range(10)
for c in a:
print 'hi'
In [ ]:
# tuples and lists are iterable
In [3]:
# dicts are iterable (over keys), but iteration is not ordered
d = { 'a': 1, 'b': 2 }
for k in d:
print k, d[k]
In [5]:
# use "zip" to iterate over multiple sequences (dict example)
a = 'fish'
b = range(4)
for x, y in zip(a,b):
print x, y