Python: Iteration and Exceptions