I am writing a code which prints all the permutations of [a,b,c,d].I don't want to use recursive function and instead I have used 4 for loops, but the disadvantage of my code is that the loops have to be the same amount as the elements of the list. My question is that wether it is possible to write a code which is independent from the number of the elements.
alphabet=["a","b","c","d"]
for first in alphabet:
for second in alphabet:
if second != first:
for third in alphabet:
if third!=second and third!=first :
for fourth in alphabet:
if fourth!=first and fourth!=second and fourth != third:
print(first,second,third,fourth)