Use compatible generator syntax

We can unify our generator syntax by using next(gen) instead of either gen.next() in py2 or gen.__next__() in py3.