0
此问题已经在Python 2.x中得到解答。我不能让它能在Python 3Python 3:找到循环中的上一个/下一个元素
我改变izip
到zip
工作,因为我明白izip从Python 3的
from itertools import tee, islice, chain
def previous_and_next(some_iterable):
prevs, items, nexts = tee(some_iterable, 3)
prevs = chain([None], prevs)
nexts = chain(islice(nexts, 1, None), [None])
print(zip(prevs, items, nexts))
a = list(range(1,10))
previous_and_next(a)
运行此移除给我<zip object at 0x7f338e4ea638>
什么是错的用这个代码?