mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-23 00:41:19 -04:00
Update and rename permutation.py to permutations.py
This commit is contained in:
parent
0b6dbbaa27
commit
a4fe8d519e
1 changed files with 1 additions and 7 deletions
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def permutation(string) -> list:
|
||||
|
||||
if len(string) == 1:
|
||||
return [string]
|
||||
|
||||
result = []
|
||||
for i, char in enumerate(string):
|
||||
for perm in permutation(string[:i] + string[i+1:]):
|
||||
result += [char + perm]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Testing permutation()...')
|
||||
string = "bt3gl"
|
||||
print(f'Permutation of {string}: {permutation(string)}')
|
Loading…
Add table
Add a link
Reference in a new issue