0

在这个快速排序功能中:

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)

我不明白评论下面的句子。有人能告诉我这里这句话是什么意思吗?

4

1 回答 1

8

它将一个元组解压缩为三个变量。

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

a, b, c = foo()
print(a) # prints "1"
print(b) # prints "2"
print(c) # prints "3"
于 2012-11-11T02:39:03.153 回答