Browse Source

更新 'tt.py'

hzhu 7 years ago
parent
commit
2d201bc399
1 changed files with 15 additions and 9 deletions
  1. 15 9
      tt.py

+ 15 - 9
tt.py

@@ -1,12 +1,20 @@
1
-s = '1 2 + 5 4 - *'
2
-L = s.split()
3
-print L
1
+def toList(s):
4 2
 
5
-def f(i,s,S=[]):
6
-    if i==len(s):
7
-        return S
3
+    L = []
4
+    for i in s:
5
+        if i != '\n':
6
+            L.append(i)
7
+    return L
8 8
 
9
-    a=s[i]
9
+def f(i,s,S = None):
10
+    
11
+    if not S:
12
+        S = []
13
+        
14
+    if i == len(s):
15
+        return S[0]
16
+
17
+    a = s[i]
10 18
     if a.isdigit():
11 19
         S.append(a)
12 20
         return f(i+1,s,S)
@@ -16,5 +24,3 @@ def f(i,s,S=[]):
16 24
         e = '%s%s%s'%(c,a,d)
17 25
         S.append(eval(e))
18 26
         return f(i+1,s,S)
19
-
20
-print f(0,L)