cours_progra/renforcement/entrainement_0311/ex4.py

25 lines
473 B
Python
Raw Normal View History

2022-11-09 16:22:14 +01:00
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')