Program - Replace negative prices with 0 and leave the positive values unchanged in a list
Topic: Program - Replace negative prices with 0 and leave the positive values unchanged in a list
Solution
original_prices = [1.25, -9.45, 10.22, 3.78, -5.92, 1.16] prices = [i if i > 0 else 0 for i in original_prices] print(f"Final List:{prices}")
List all Python Programs