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)
>>> 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM