为了压缩我的代码,我试图将我的一个while循环变成一个函数。我已经尝试了很多次,并且在编译时还没有收到与我离开while循环时相同的结果。
这是while循环:
while True:
i = find_lowest_i(logs)
if i == -1:
break
print "i=", i
tpl = logs[i].pop(0)
print tpl
out.append(tpl)
print out
以下是我迄今为止的功能:
def mergesort(list_of_logs):
i = find_lowest_i(logs)
out = []
while True:
if i == -1:
break
print "i=", i
tpl = logs[i].pop(0)
print tpl
out.append(tpl)
print out
return out
提前致谢。这个地方是初学者程序员的避风港。
答案 0 :(得分:0)
看起来你的函数的参数是list_of_logs
,你仍然在函数体内使用logs
。最简单的修复方法可能是将参数从mergesort
重命名为list_of_logs
到logs
。否则,对我来说看起来完全正确。