You can use zip .
>>> list(zip(range(5), range(2, 6))) [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)]
Like lightning, it creates pairs. So, to mix your two lists, you get:
>>> l = [1,7,3,5] >>> list(zip(l[:-1], l[1:])) [(1, 7), (7, 3), (3, 5)]
Then the repetition is performed as
for x, y in zip(l[:-1], l[1:]): pass
Noctua Jan 23 '14 at 8:48 2014-01-23 08:48
source share