@@ -5,7 +5,7 @@ def fact(n):
5
5
if n == 0 :
6
6
return 1
7
7
else :
8
- return n * fact (n - 1 )
8
+ return n * fact (n - 1 )
9
9
10
10
11
11
def print_num (n ):
@@ -15,14 +15,14 @@ def print_num(n):
15
15
16
16
def print_num_recursive (n ):
17
17
if n > 0 :
18
- print_num_recursive (n - 1 )
18
+ print_num_recursive (n - 1 )
19
19
print (n )
20
20
21
21
22
22
def print_num_recursive_revserve (n ):
23
23
if n > 0 :
24
24
print (n )
25
- print_num_recursive_revserve (n - 1 )
25
+ print_num_recursive_revserve (n - 1 )
26
26
27
27
28
28
from collections import deque
@@ -54,6 +54,19 @@ def print_num_use_stack(n):
54
54
55
55
def hanoi_move (n , source , dest , intermediate ):
56
56
if n >= 1 : # 递归出口,只剩一个盘子
57
- hanoi_move (n - 1 , source , intermediate , dest )
57
+ hanoi_move (n - 1 , source , intermediate , dest )
58
58
print ("Move %s -> %s" % (source , dest ))
59
- hanoi_move (n - 1 , intermediate , dest , source )
59
+ hanoi_move (n - 1 , intermediate , dest , source )
60
+
61
+
62
+ def flatten (rec_list ):
63
+ for i in rec_list :
64
+ if isinstance (i , list ):
65
+ for i in flatten (i ):
66
+ yield i
67
+ else :
68
+ yield i
69
+
70
+
71
+ def test_flatten ():
72
+ assert list (flatten ([[[1 ], 2 , 3 ], [1 , 2 , 3 ]])) == [1 , 2 , 3 , 1 , 2 , 3 ]
0 commit comments