Python Practice › Tuple Programs › Program 16

Multiply adjacent elements

EasyTuple Programs · 16 of 70

Write a Python program to multiply each pair of neighbouring elements of a tuple.

Advertisement
Input
(1, 2, 3, 4)
Output
(2, 6, 12)

Approach

  1. zip(t, t[1:]) gives the neighbours.

Solution

Python
t = (1, 2, 3, 4)print(tuple(a * b for a, b in zip(t, t[1:])))
Output
(2, 6, 12)
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs