Python Practice › Tuple Programs › Program 52

Multiply the ith element of each tuple

EasyTuple Programs · 52 of 70

Write a Python program to multiply the elements at index i of every tuple.

Advertisement
Input
[(4, 8, 3), (3, 4, 0), (1, 6, 2)], i = 1
Output
192

Approach

  1. math.prod(t[i] for t in data).

Solution

Python
import mathdata = [(4, 8, 3), (3, 4, 0), (1, 6, 2)]print(math.prod(t[1] for t in data))
Output
192
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs