.
This commit is contained in:
24
bac1/q1/renforcement/entrainement_0311/ex4.py
Normal file
24
bac1/q1/renforcement/entrainement_0311/ex4.py
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
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')
|
||||
|
Reference in New Issue
Block a user