cours_progra/bac1/q1/renforcement/entrainement_0311/ex4.py
Debucquoy 4fd7542f03
.
2023-09-20 15:18:20 +02:00

25 lines
473 B
Python

def permutation(mot):
"""find all permutation of a word
:mot: TODO
:returns: list of all permutations
"""
return permutation_rec('' , mot)
def permutation_rec(pre, post):
print(pre, post)
if (post == ''):
return pre
ret = list()
for i in list(post):
_post = list(post)
_post.remove(i)
ret.append(permutation_rec(pre + i, str(_post)))
return ret
if __name__ == "__main__":
permutation('abc')