python-101 icon indicating copy to clipboard operation
python-101 copied to clipboard

Remove redundant comparison in 32_stonks.py

Open owljacob opened this issue 7 months ago • 0 comments

The code for min_price can be improved by removing redundant comparison.

def min_price(a, b):
  mn = price_at(a)
  for i in range(a, b + 1):
    mn = min(mn, price_at(i))
  return mn

mn is initialized with the value of price_at(a) and that, however, means that the line where mn is updated becomes mn = min(price_at(a), price_at(a)), this is redundant and it's possible to skip it.

owljacob avatar Jun 16 '25 12:06 owljacob