Python Practice › Tuple Programs › Program 16
Multiply adjacent elements
Write a Python program to multiply each pair of neighbouring elements of a tuple.
Input
(1, 2, 3, 4)
Output
(2, 6, 12)
Approach
zip(t, t[1:])gives the neighbours.
Solution
t = (1, 2, 3, 4)print(tuple(a * b for a, b in zip(t, t[1:])))Output
(2, 6, 12)
Learn the concept
New to this topic? Read the lesson, then come back.