Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator
- arr = ['+',2,2,'-',1]
- ops = {'+': sum, '-':operator.sub}
- res = 0
- cur_op = None
- for x in arr:
- if type(x) == int:
- if cur_op == sum:
- res = cur_op([res, x])
- else:
- res = cur_op(res, x)
- else:
- cur_op = ops.get(x)
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement