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)