How to multiply the columns of a nested list in Python

1 Answer

0 votes
import functools

nested_list = [[1, 2, 3],
               [4, 5, 6],
               [7, 8, 9]]
               
column_product = [functools.reduce(lambda x, y: x * y, column) for column in zip(*nested_list)]

print("The column product:", column_product)

 
 
'''
run:
 
The column product: [28, 80, 162]
 
'''

 



answered Jan 10 by avibootz
...