Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 将while循环转换为函数?python_Function_While Loop_Python 2.7 - Fatal编程技术网

Function 将while循环转换为函数?python

Function 将while循环转换为函数?python,function,while-loop,python-2.7,Function,While Loop,Python 2.7,为了压缩我的代码,我正在尝试将我的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 到目前为止

为了压缩我的代码,我正在尝试将我的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

提前谢谢。这个地方是初学者程序员的避风港

您的函数的参数似乎是日志列表,并且您仍然在函数体中使用日志。最简单的修复方法可能是将参数重命名为mergesort,从\u日志的列表\u到日志。否则,在我看来完全正确。

谢谢!真不敢相信我没听懂。