- 2

# Write a program to find a permutation of string or a word

permutation mean a how many ways to arrage a word to find different word by given word as examples we can write ABC IN PERMUTATION AS ABC BCA CAB ACB BAC ACB CBA as like that different arrangements of ABC

2 Answers

+ 1

You want to do recursion, so you first have to find out how the recursion would work. In this case it is the following:
permutation [a,b,c,...] = [a + permutation[b,c,...], b + permutation[a,c,..], ...]
And as a final condition:
permutation [a] = [a]
So the recursion splits up the list in sublists with one element extracted each time. Then this element is added to the front of each of the permutations of the sublist.
So in pseudo-code:
def permutation(s):
if len(s) == 1:
return [s]
perm_list = [] # resulting list
for a in s:
remaining_elements = [x for x in s if x != a]
z = permutation(remaining_elements) # permutations of sublist
for t in z:
perm_list.append([a] + t)
return perm_list

- 1

https://code.sololearn.com/coiWnuyDI8W2/?ref=app
This is a coding challenge
https://www.sololearn.com/learn/9885/?ref=app