fork download
  1. import operator
  2.  
  3. def calc(lst):
  4.  
  5. op = {
  6. '/': operator.truediv(lst[0], lst[2]),
  7. '+': operator.add(lst[0], lst[2]),
  8. }
  9.  
  10. return op[lst[1]]
  11.  
  12.  
  13. print(calc([1, '/' , 2]))
  14. print(calc([1, '+' , 2]))
  15.  
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
0.5
3