标签: python python-3.x
我有一个字符串"dog",我不想用该字母的字母生成所有可能的组合。
"dog"
输出将是这样的:
["dog","dgo","ogd","odg","god","gdo"]
订单根本不重要。
答案 0 :(得分:2)
使用itertools.permutations:
import itertools word = 'dog' result = [''.join(new_word) for new_word in itertools.permutations(word)] print(result)