0
Is there a shorter way of getting all string permutations than the following?
from itertools import accumulate, permutations def str_perm(s): return list(map(lambda x: list(accumulate(x))[len(x)-1], list(permutations(s)))) print(str_perm("abcd"))
1 Respuesta
0
Turns out accumulate can be replaced with join:
from itertools import permutations
def str_perm(s):
# '' - is an empty string here
return [''.join(p) for p in permutations(s)]
print(str_perm("abcd"))