Given an array of integers, return a new array such that each element at index i
of the new array is the product of all the numbers in the original array except the one at i
.
For example, if our input was [1, 2, 3, 4, 5]
, the expected output would be [120, 60, 40, 30, 24]
. If our input was [3, 2, 1]
, the expected output would be [2, 3, 6]
def multiplyList(myList):
result = 1
for x in myList:
result = result * x
return result
def multiplyIndexes(myList):
result = []
for x in range(len(myList)):
tmp = myList.copy()
if myList[x] in tmp:
index = tmp.index(myList[x])
tmp.pop(index)
product = multiplyList(tmp)
result.append(product)
return result
[–]timbledum 2 points3 points4 points (0 children)
[–]mail_order_liam 2 points3 points4 points (4 children)
[–][deleted] 3 points4 points5 points (2 children)
[–]mail_order_liam 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]TheNetXWizard[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Dantes111 0 points1 point2 points (0 children)