1def max_profit(prices):2    max_p = 03    min_buy = prices[0]4    for sell in prices:5        max_p = max(max_p, sell - min_buy)6        min_buy = min(min_buy, sell)7    return max_p