I have a program that finds the highest and lowest values in an array, excludes them, then sums up the rest of the numbers in that array. It works with most random inputs, except for cases when there are duplicates of the highest or the lowest number in that array
def sum_array(arr):
if arr is None:
return 0
if len(arr) < 2:
return 0
return sum([i for i in arr if i != max(arr) and i != min(arr)])
In which case if I print(sum_array([6, 0, 1, 10, 10])), it only returns 7 instead of 17.
It excluded the highest number entirely.
How do I make the program recognize that there are duplicates and take just one of them for the sum so, in this case, it can return 17?