0
我试图运行一个函数来创建一个列表。在Python中使用递归函数中的新列表
唯一的问题是它的递归函数,所以如果我定义了我用作 list=[]
的新列表,那么每次运行它时列表都会自行清空,如果我不这样做,新列表是说来不被定义
代码示例:
def rec (a_list_of_numbers):
if a_list_of_numbers==[]:
return 0
newlist=[] ##the problem is here
newlist.append(rec(**some sort of recursion here**)+rec(**some sort of recursion here**)
return newlist
请张贴实际的代码,并告诉我们究竟是什么问题。 –
你可以在'**某种递归这里**'展开吗? – Eric
你想要结果列表是什么? – phant0m