排列问题

def permutation_all_1(L):
    if len(L) <= 1: return [L]
    T = permutation_all_1(L[1:])
    R = []
    # 循环方式一:
    for i in range(len(L)):
        for t in T:
            # 循环方式二:
            # for t in T:
            #     for i in range(len(L)):

            x = t[0:i] + [L[0]] + t[i:]
            if x not in R:
                R.append(x)
    return R


def permutation_all_2(L):
    if len(L) <= 1: return [L]
    R = []
    for i in range(len(L)):
        L0 = L[0:i] + L[i+1:]
        T = permutation_all_1(L0)
        for t in T:
            x=[L[i]]+t
            if x not in R:
                R.append(x)
    return R

# L = [8, 3, 5, 5]
# res1 = permutation_all_1(L)
# print(res1)

L2 = [ 3, 5, 8]
res2 = permutation_all_2(L2)
print(res2)
上一篇:31. Next Permutation


下一篇:WebADI_案例实施03_利用FND_LOAD安装和迁移WEBADI以及设定(案例)