With a decrease and Python <3.x:
from itertools import tee, izip
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
reduce(lambda s, (x, y):s + x * y, pairwise(topo), 0)
with card:
from operator import mul
from itertools import tee
a, b = tee(topo)
next(b, None)
sum(map(mul, a, b))
source
share