MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / product_sum_array

Function product_sum_array

data_structures/arrays/product_sum.py:67–92  ·  view source on GitHub ↗

Calculates the product sum of an array. Args: array (List[Union[int, List]]): The array of integers and nested lists. Returns: int: The product sum of the array. Examples: >>> product_sum_array([1, 2, 3]) 6 >>> product_sum_array([1, [2, 3]]

(array: list[int | list])

Source from the content-addressed store, hash-verified

65
66
67def product_sum_array(array: list[int | list]) -> int:
68 """
69 Calculates the product sum of an array.
70
71 Args:
72 array (List[Union[int, List]]): The array of integers and nested lists.
73
74 Returns:
75 int: The product sum of the array.
76
77 Examples:
78 >>> product_sum_array([1, 2, 3])
79 6
80 >>> product_sum_array([1, [2, 3]])
81 11
82 >>> product_sum_array([1, [2, [3, 4]]])
83 47
84 >>> product_sum_array([0])
85 0
86 >>> product_sum_array([-3.5, [1, [0.5]]])
87 1.5
88 >>> product_sum_array([1, -2])
89 -1
90
91 """
92 return product_sum(array, 1)
93
94
95if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

product_sumFunction · 0.85

Tested by

no test coverage detected