def mot (n) :
if n==0 :
yield n
else :
for m in mot(n-1) :
yield [m]
for k in range(0,n-1) :
for l in mot(k) :
for r in mot(n-2-k) :
yield (l,r)
def countFor(f,n) :
for i in range(n) :
count = 0
for t in f(i) :
count+=1
yield count
def countsFor(mes,f,n) :
print(mes)
print([c for c in countFor(f,n)])
print("")
def showFor(mes,f,n) :
print(mes)
for t in f(n) :
print(t)
print("")
showFor('Motzkin trees',mot,4)
countsFor('Motzkin trees',mot,12)
print("done")
def test() :
for n in range(6) :
print(n,list(mot(n)))
我有以下输出 motzkin 数字的代码,我想将 yield 表达式更改为另一个更简单的表达式或函数,我该怎么做,我该怎么办?谢谢