solution.py 502 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
def permutation(data):
    if len(data) < 2:
        yield data
        return

    if len(data) == 2:
        yield data
        yield data[1]+data[0]
        return
        
    for i in range(len(data)):
        element = data[i]
        sub = data[:i] + data[i+1:]
        for token in permutation(sub):
                yield element + token

if __name__ == "__main__":
    word = input("input:")
M
Mars Liu 已提交
19 20 21 22
    result = [t for t in permutation(word)]
    result.sort()
    for e in result:
        print(e)
M
Mars Liu 已提交
23