How to multiply the elements of each tuple in a list of tuples in Python

1 Answer

0 votes
import math

list_of_tuples = [(1, 2), (3, 4), (5, 6), (7, 8)]

result_lst = [math.prod(tpl) for tpl in list_of_tuples]

print(result_lst)

 
   
   
   
'''
run:
   
[2, 12, 30, 56]
 
'''

 



answered Jul 24, 2022 by avibootz
...