Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
一种使用Python的方法,我不知道';我不知道_Python - Fatal编程技术网

一种使用Python的方法,我不知道';我不知道

一种使用Python的方法,我不知道';我不知道,python,Python,在此快速排序函数中: def qsort2(list): if list == []: return [] else: pivot = list[0] # can't understand the following line lesser, equal, greater = partition(list[1:], [], [pivot], []) return qsort2(lesser) + equal

在此快速排序函数中:

def qsort2(list):
    if list == []: 
        return []
    else:
        pivot = list[0]
        # can't understand the following line
        lesser, equal, greater = partition(list[1:], [], [pivot], [])
    return qsort2(lesser) + equal + qsort2(greater)

def partition(list, l, e, g):
    if list == []:
        return (l, e, g)
    else:
        head = list[0]
        if head < e[0]:
            return partition(list[1:], l + [head], e, g)
        elif head > e[0]:
            return partition(list[1:], l, e, g + [head])
        else:
            return partition(list[1:], l, e + [head], g)
def qsort2(列表):
如果列表=[]:
返回[]
其他:
pivot=列表[0]
#我听不懂下面这句话
较小、相等、较大=分区(列表[1:]、[]、[pivot]、])
返回qsort2(较小)+相等+qsort2(较大)
def分区(列表、l、e、g):
如果列表=[]:
返回(l、e、g)
其他:
head=列表[0]
如果磁头e[0]:
返回分区(列表[1:],l,e,g+[head])
其他:
返回分区(列表[1:],l,e+[head],g)

我不明白评论下面的句子。有人能告诉我这个句子的意思吗?

它把一个元组分解成三个变量

def foo():
    return (1, 2, 3)

a, b, c = foo()
print(a) # prints "1"
print(b) # prints "2"
print(c) # prints "3"

谢谢,但是分区消耗了4项,这里我们只有3项,第一项呢?它是关于
partition
返回的内容,这是一个3元组(
return(l,e,g)
)。非常感谢,所以关于第一项并不重要。它与传递给
分区的参数无关。顺便说一下,使用“list”作为变量名不是一个好主意——“list”已经是python内置的名称,在某些情况下重新定义该名称可能会导致奇怪的行为。您的代码可能会工作,但您确实希望现在就养成谨慎的习惯,而不是以后以艰难的方式找到边缘情况。