Use the next() builtin for Python 3 compatibility

`iterator.next()` has been replaced by `next(iterator)` in Python 3.