If at every element you need something like "the sum of the numbers to its left" or "the lowest price so far", do not work it out from the start each time. Update it as you go: add the new element to the value from before.
total = sum(values)left = 0for i, v in enumerate(values):if left == total - left - v:return ileft += vreturn -1
enumerate gives the position and the value together. The sum on the right needs no variable of its own: take the left and the element itself from the total and the right is what remains. left grows after the comparison.The best buy-and-sell is the same idea: carry "the lowest price up to today" and the profit of selling today is one subtraction. One pass in place of two nested loops.