Using 'next' function for Python 3 compatibility.

http://docs.pythonsprints.com/python3_porting/py-porting.html#iterators