Python algorithm question: Sum of two lowest positive integers

Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 integers. No floats or empty arrays will be passed.

For example, when an array is passed like [19, 5, 42, 2, 77], the output should be 7.

[10, 343445353, 3453445, 3453545353453] should return 3453455.


The idea is clearer:

#sum of the two smallest numbers in the list
def sum_two_smallest_numbers(numbers):
    i=min(numbers)
    numbers.remove(i)
    j=min(numbers)
    return i+j

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325481155&siteId=291194637