Hello, I would like to do something so you can help me since I have been searching and I can't find any function that subtracts the elements of an array
array1 = [1, 5, 2]
resta = restar elementos de array1 = 5 - 2 - 1
resta = 2
Hello, I would like to do something so you can help me since I have been searching and I can't find any function that subtracts the elements of an array
array1 = [1, 5, 2]
resta = restar elementos de array1 = 5 - 2 - 1
resta = 2
If you want to subtract from the largest number to the smallest number, you would first have to order the elements of the array from largest to smallest, you can do this with the method
sort(reverse=True)
:Now, to this last result, you could apply the method
reduce()
to subtract the elements of the array. To do this, you should import the packagefunctools
, your code would be like this:Links: