并[a,A,B,A]
我想生成这个数字的排列结果的数量必须是4因为重复的字符有人可以帮我在python中编码
发布于 2018-09-17 09:46:06
运用 itertools.permutations
>>> import itertools
>>> a,b = 1,2
>>> set(itertools.permutations([a,a,b,a]))
{(1, 1, 2, 1), (2, 1, 1, 1), (1, 2, 1, 1), (1, 1, 1, 2)}
或者使用more_itertools.distinc
t_permutations
>>> import more_itertools
>>> a,b = 1,2
>>> list(more_itertools.distinct_permutations([a,a,b,a]))
[(2, 1, 1, 1), (1, 2, 1, 1), (1, 1, 2, 1), (1, 1, 1, 2)]
https://stackoverflow.com/questions/-100002636
复制相似问题