cours_progra/q1/renforcement/entrainement_0311/ex4.py
2023-02-15 13:40:50 +01: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')