本文實例講述了Python實現(xiàn)的排列組合計算操作。分享給大家供大家參考,具體如下:
1. 調(diào)用 scipy 計算排列組合的具體數(shù)值

>> from scipy.special import comb, perm>> perm(3, 2)6.0>> comb(3, 2)3.0
2. 調(diào)用 itertools 獲取排列組合的全部情況數(shù)
>> from itertools import combinations, permutations>> permutations([1, 2, 3], 2)<itertools.permutations at 0x7febfd880fc0> # 可迭代對象>> 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)]
希望本文所述對大家Python程序設(shè)計有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選