From 4a545dd88edd9eb24c6152448c4c851503958142 Mon Sep 17 00:00:00 2001 From: Kashyap Shah Date: Sun, 9 Oct 2022 01:33:44 +0530 Subject: [PATCH] Create matrixProduct.py --- Hactoberfest2020/matrixProduct.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Hactoberfest2020/matrixProduct.py diff --git a/Hactoberfest2020/matrixProduct.py b/Hactoberfest2020/matrixProduct.py new file mode 100644 index 00000000..08f6d072 --- /dev/null +++ b/Hactoberfest2020/matrixProduct.py @@ -0,0 +1,19 @@ +# getting Product +def prod(val) : + res = 1 + for ele in val: + res *= ele + return res + +# initializing list +test_list = [[1, 4, 5], [7, 3], [4], [46, 7, 3]] + +# printing original list +print("The original list : " + str(test_list)) + +# using list comprehension + loop +# Matrix Product +res = prod([ele for sub in test_list for ele in sub]) + +# print result +print("The total element product in lists is : " + str(res))