【发布时间】:2019-12-08 17:42:55
【问题描述】:
在我的代码中,我的返回值被附加到列表中。将所有项目附加到单个列表的方法是什么?现在,每个堆栈都会创建一个列表并返回该列表。
def palindrome_partition(string):
if len(string) <=2:
rev = string[::-1]
if string == rev:
return string
else:
return
pal = []
b = string[1:-1]
if len(b) <=1:
return
a = b[::-1]
res = palindrome_partition(b)
if res is not None:
pal.append(res)
if a == b:
pal.append(b)
return pal
结果是[[[],]]
想要的结果[ , , ]
【问题讨论】:
-
想要的结果是什么?
-
想要的结果:[ , , ]
标签: python recursion palindrome