本文實例講述了Python實現的排列組合計算操作。分享給大家供大家參考,具體如下:
1. 調用 scipy 計算排列組合的具體數值
>> from scipy.special import comb, perm
>> perm(3, 2)
6.0
>> comb(3, 2)
3.0
2. 調用 itertools 獲取排列組合的全部情況數
>> from itertools import combinations, permutations
>> permutations([1, 2, 3], 2)
# 可迭代對象
>> list(permutations([1, 2, 3], 2))
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
>> list(combinations([1, 2, 3], 2))
[(1, 2), (1, 3), (2, 3)]
PS:這里再為大家推薦幾款計算工具供大家進一步參考借鑒:
在線一元函數(方程)求解計算工具:http://tools.jb51.net/jisuanqi/equ_jisuanqi
科學計算器在線使用_高級計算器在線計算:http://tools.jb51.net/jisuanqi/jsqkexue
在線計算器_標準計算器:http://tools.jb51.net/jisuanqi/jsq
更多關于Python相關內容感興趣的讀者可查看本站專題:《Python數學運算技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設計有所幫助。
時間: 2017-10-11