Apr-09-2021, 12:36 PM
(Apr-09-2021, 06:48 AM)SantiagoPB Wrote: I found the solution!!!
CODE WORKING
def stringPermutations(string, prefix, permutation_list): if len(string) == 0: permutation_list.append(prefix) else: for i in range(len(string)): rem = string[0:i] + string[i + 1:] stringPermutations(rem, prefix + string[i], permutation_list) return sorted(list(dict.fromkeys(permutation_list))) def main(): n = int(input("write size: ")) b = str(input("Write String: ")) permutation_list = [] * n print(stringPermutations(n, b, " ", permutation_list)) if __name__ == '__main__': main()As you can see I just put the variable n inside of the print
Interesting, but your code doesn't run for me.
stringPermutations
expects 3 arguments but is receiving 4 in line 13, so on my system that is resulting in a TypeError.