s = '1 2 + 5 4 - *' L = s.split() print L def f(i,s,S=[]): if i==len(s): return S a=s[i] if a.isdigit(): S.append(a) return f(i+1,s,S) else: c = S.pop() d = S.pop() e = '%s%s%s'%(c,a,d) S.append(eval(e)) return f(i+1,s,S) print f(0,L)