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

タプルを 3 つの変数にアンパックします。

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 に答える