Я придумал вот такое решение, но оно мне не очень нравится. Например, сумма текущего и предыдущего элементов:
lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for n in lst:
print n + lst[lst.index(n) - 1]
lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for n in lst:
print n + lst[lst.index(n) - 1]
l = [...]
for i in range(len(l)):
pre = l[i-1] if i > 0 else None
curr = l[i]
next = l[i+1] if i < len(l) - 1 else None
l = [...]
assert len(l) >= 3
for i in range(1, len(l)-1):
pre = l[i-1]
curr = l[i]
next = l[i+1]
import itertools
ls = [1, 2, 3, 4, 5, 6]
for prev, curr, next in map(None, itertools.chain((None,), ls[:-1]), ls, ls[1:]):
print prev, curr, next
None 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 None
for prev, curr, next in itertools.izip(itertools.chain([None], ls[:-1]), ls, itertools.chain(ls[1:], [None])):
print prev, curr, next