solution.py 457 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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:")
    for line in permutation(word):
        print(line)