Is there a shorter way of getting all string permutations than the following? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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"))

5th Oct 2016, 10:12 AM
novice
1 Réponse
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"))
6th Oct 2016, 12:15 AM
novice