itertools.cycle().next()?

前端 未结 2 1195
醉酒成梦
醉酒成梦 2020-12-05 12:59

Well, I was using itertools.cycle().next() method with Python 2.6.6, but now that I updated to 3.2 I noticed that itertools.cycle() object has no m

相关标签:
2条回答
  • 2020-12-05 13:35

    iter.next() was removed in python 3. Use next(iter) instead. So in your example change itertools.cycle().next() to next(itertools.cycle())

    There is a good example here along with various other porting to python 3 tips. It also compares various other next() idioms in python 2.x vs python 3.x

    0 讨论(0)
  • 2020-12-05 13:38

    In Python 3.x, iterators don't have it.next() any more. use next(it) instead, which also works in Python 2.6 or above. Internally, this will call it.next() in Python 2.x and it.__next__() in Python 3.x.

    0 讨论(0)
提交回复
热议问题