I was trying to create a code to display all possible permutations of a string without using itertools, so I came up with a basic idea of how I could get this to work using these ugly nested for-loops but now I want to convert this into a function for any string with length 'n', I'm kinda new to recursion so I need some help sorting this out.
wrdinp=input("Enter a word: ")
d=[]
#Works for string with length 4
for a in wrdinp:
for b in wrdinp:
if b!=a:
for c in wrdinp:
if c!=a and c!=b:
for d in wrdinp:
if d!=a and d!=b and d!=c:
d.append(a+b+c+d)
print("Permutations:",d)
I need a function that takes in a string of any length and returns a list that contains the various permutations of the string.