mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -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
16
arrays_and_strings/permutations.py
Normal file
16
arrays_and_strings/permutations.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def permutations(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
|
Loading…
Add table
Add a link
Reference in a new issue