The function below mutates its input list — a classic source of bugs.
# dirty — mutates the original list!
def solve(cart, item):
cart.append(item)
cart.sort(key=lambda x: x['price'])
return cartRefactor `solve(cart, item)` so it returns a new sorted list without modifying cart.
After calling solve(cart, item), the original cart list must be unchanged.
Sample tests