Open this example in the interactive library
Source code
from itertools import pairwise
print(list(pairwise([1, 4, 9, 16])))Sample output
[(1, 4), (4, 9), (9, 16)]

Pair adjacent values. A self-contained example using the Python standard library.
Open this example in the interactive library
from itertools import pairwise
print(list(pairwise([1, 4, 9, 16])))[(1, 4), (4, 9), (9, 16)]