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>
什麼是錯的用這個代碼?