临摹微笑
itertools成对配方适用于任何迭代from itertools import tee, izipdef pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return izip(a, b)path = ['a', 'b', 'c', 'd', 'e']>>> for x, y in pairwise(path): print x, ya bb cc dd e>>> list(pairwise(path))[('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e')]