【发布时间】:2018-09-15 16:35:21
【问题描述】:
我想返回列表的最终值 new_list[3] 但它最后什么也不返回。我可以使用 print 函数获得 new_list[3] 的最终值。我对返回函数感到很困惑。 2 for 循环结束时是否有可能返回 new_list[times] ?
original_list = [100,300,400,900,1500]
def filter_list(_list,times):
L = len(_list)
new_list = [list(_list) for k in range(times+1)]
for k in range (0,times):
for j in range (0,L):
if j == 0: #exclude the term [j-1] because new_list[-1] is not exist
new_list[k+1][j] = int(new_list[k][j]*0.2 + new_list[k][j+1]*0.5)
elif j == L-1: #exclude the term [j+1] because new_list[L] is not exist
new_list[k+1][j] = int(new_list[k][j-1]*0.4 + new_list[k][j]*0.2)
else:
new_list[k+1][j] = int(new_list[k][j-1]*0.4 + new_list[k][j]*0.2 + new_list[k][j+1]*0.5)
return (new_list[times])
filter_list(original_list,3)
【问题讨论】:
-
我收到
[263, 561, 744, 763, 436]。 -
你
print(filter_list(original_list,3))看到结果了吗? -
@Austin 我用的是jupyter notebook,自动打印最后一行!
-
@KhalilAlHooti OP 可能没有使用 Jupyter 笔记本。 ;)
-
@Austin 我认为他的功能本身有问题,而不是缺少打印输出。!!
标签: python python-3.6