jack-zheng
3/23/2018 - 11:35 AM

python, exercise, iterator

python, exercise, iterator

when use python in the way below, there will be an exception:

In [19]: it = iter([1,2,3])
In [20]: it.next()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-24d6ab57088b> in <module>()
----> 1 it.next()

AttributeError: 'list_iterator' object has no attribute 'next'

this is a syntax change between python2 and python3. in 3 you can use next(it) instead.