Apply Discount to Prices LeetCode solution in Python
1class Solution:2def discountPrices(self, sentence: str, discount: int) -> str:3s = sentence.split() # convert to List to easily update4m = discount / 1005for i, word in enumerate(s):6if (7word[0] == "$" and word[1:].isdigit()8): # Check whether it is in correct format9num = int(word[1:]) * (1 - m) # discounted price10w = "$" + "{:.2f}".format(num) # correctly format11s[i] = w # Change inside the list1213return " ".join(s) # Combine the updated list