Fixed iteration to work in Python 2.x and Python 3.x