python-排列组合函数itertools.permutations

 

输入两个参数分别为:可迭代对象,从可迭代对象中取出几个值来计算其排列

>>> from itertools import permutations
>>> permutations(a,3)
<itertools.permutations object at 0x000002216C0799F0>
>>> print(permutations(a,3))
<itertools.permutations object at 0x000002216E117270>
>>> type(permutations(a,3))
<class itertools.permutations>
>>> 
>>> 
>>> 
>>> 
>>> for i in permutations(ABC,3):
    print(i)

    
(A, B, C)
(A, C, B)
(B, A, C)
(B, C, A)
(C, A, B)
(C, B, A)
>>> 
>>> for i in permutations(a,3):
    print(i)

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

 

python-排列组合函数itertools.permutations

上一篇:go_["a","a","b","b","c","c","c"]非数字数组json.Unmarshal()方法不支持


下一篇:UWP使用AppService向另一个UWP客户端应用程序提供服务