Maximum contiguous sum in an array
I would merge the 2 loops (there is one in the max part), since not all parts are relevant for the maximum:

def best_subsum(array):
    running_sum = 0
    for i in range(1,len(array)):
        if array[i-1] &gt; 0:
            array[i] = array[i] + array[i-1]
            if array[i] &gt; running_sum: running_sum = array[i]
    return running_sum

array = [4, -2, 7, -9]
print(best_subsum(array))


Note that branch prediction shouldnt be too much of a problem, since running sum is not check until the same if statement in the next succeding iteration.