Apply Discount to Prices LeetCode solution in Python

1
class Solution:
2
def discountPrices(self, sentence: str, discount: int) -> str:
3
s = sentence.split() # convert to List to easily update
4
m = discount / 100
5
for i, word in enumerate(s):
6
if (
7
word[0] == "$" and word[1:].isdigit()
8
): # Check whether it is in correct format
9
num = int(word[1:]) * (1 - m) # discounted price
10
w = "$" + "{:.2f}".format(num) # correctly format
11
s[i] = w # Change inside the list
12

13
return " ".join(s) # Combine the updated list

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0