Update and rename permutation.py to permutations.py

This commit is contained in:
marina 2023-08-07 17:34:32 -07:00 committed by GitHub
parent 0b6dbbaa27
commit a4fe8d519e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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