basic calculator II

🏠
 1 def calculate(S):
 2     S, s, n, p = f"{S}+0", [], 0, "+"
 3     ops = {
 4         "-": lambda x: s.append(-x),
 5         "+": lambda x: s.append(x),
 6         "*": lambda x: s.append(s.pop() * x),
 7         "/": lambda x: s.append(int(s.pop() / x)),
 8     }
 9     for i in range(len(S)):
10         if S[i].isdigit():
11             n = n * 10 + int(S[i])
12         elif not S[i].isspace():
13             ops[p](n)
14             n, p = 0, S[i]
15     return sum(s)
16 
17 print(calculate("3+59*10/100"))