输入一个长度为 n 字符串,打印出该字符串中字符的所有排列,你可以以任意顺序返回这个字符串数组。
例如输入字符串ABC,则输出由字符A,B,C所能排列出来的所有字符串ABC,ACB,BAC,BCA,CBA和CAB。
from itertools import permutations
def string_permutations(s):
perm_list = [''.join(p) for p in permutations(s)]
perm_list=list(set(perm_list))
return perm_list
# Example usage:
input_string = "aab"
result = string_permutations(input_string)
print(result)