我试图从递归循环中创建一个列表。我知道它能够产生我需要的结果,因为我已经通过打印结果检查了它。
这是我的递归循环:
def move_forward_occurences(occurrences, firstListDt):
listingResults = []
for x in range(0, occurrences):
firstListDt = firstListDt + relativedelta(bdays=+2)
listingResults.extend(firstListDt)
return listingResults
或者,问题可能是我没有正确检查:
if occurrences != 0:
listingResult = move_forward_occurences(occurrences, firstListDt)
for result in listingResult:
print(result)
如果需要,可以对参数进行解释(它们已经非常自我解释): occurrence =生成结果的次数 firstListDt =开始日期
提前致谢!
答案 0 :(得分:0)
您的return
过度缩进。您希望将返回推迟到for
循环结束后:
def move_forward_occurences(occurrences, firstListDt):
listingResults = []
for x in range(0, occurrences):
firstListDt = firstListDt + relativedelta(bdays=+2)
listingResults.extend(firstListDt)
return listingResults