python itertools之排序组合

>>> import itertools
>>> list(itertools.permutations([1,2,3],2))
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
>>> list(itertools.permutations([1,2,3],3))
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
>>> set(itertools.permutations([1,2,3],3))
{(1, 3, 2), (3, 2, 1), (2, 1, 3), (3, 1, 2), (1, 2, 3), (2, 3, 1)}
>>> tuple(itertools.permutations([1,2,3],3))

((1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1))

>>> set(itertools.permutations('ABC',2))
{('B', 'C'), ('B', 'A'), ('C', 'A'), ('C', 'B'), ('A', 'B'), ('A', 'C')}
>>>



真是个神奇的东西,大大的有用,呵呵


你可能感兴趣的:(c,python,list,import)