Python Practice › Tuple Programs › Program 52
Multiply the ith element of each tuple
Write a Python program to multiply the elements at index i of every tuple.
Input
[(4, 8, 3), (3, 4, 0), (1, 6, 2)], i = 1
Output
192
Approach
math.prod(t[i] for t in data).
Solution
import mathdata = [(4, 8, 3), (3, 4, 0), (1, 6, 2)]print(math.prod(t[1] for t in data))Output
192
Learn the concept
New to this topic? Read the lesson, then come back.