Say I have an array:
[44, 30, 24, 32, 35, 30, 40, 38, 15]
Here, every number represents a stock value on a certain day. I want to find the maximum profit that could have been made by buying stock on day x and selling stock on day y.
In this case, the function would return 16, because at index 2 the stock was worth $24 and at index 6 the stock was then worth $40.
Here is my attempt, however I can't figure out how to only look at consecutive elements in the list
x = [5, 8, 15, 19] # total scores
y = [x[i] - x[i-1] if i else x[i] for i in range(len(x))] # round scores
print(y)
# output
[5, 3, 7, 4]
max(((t1-e1,(e1,t1)) for i,e1 in enumerate(your_list) for t1 in li[i+1:]))