Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. import operator
  2. arr = ['+',2,2,'-',1]
  3. ops = {'+': sum, '-':operator.sub}
  4. res = 0
  5. cur_op = None
  6. for x in arr:
  7.     if type(x) == int:
  8.         if cur_op == sum:
  9.             res = cur_op([res, x])
  10.         else:
  11.             res = cur_op(res, x)
  12.     else:
  13.         cur_op = ops.get(x)
  14.  
  15. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement