欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python 排列組合之itertools

 更新時間:2013年03月20日 20:53:51   作者:  
python 排列組合之itertools,需要的朋友可以參考一下
python 2.6 引入了itertools模塊,使得排列組合的實現(xiàn)非常簡單:
復制代碼 代碼如下:

import itertools 

有序排列:e.g., 4個數(shù)內(nèi)選2個排列:
復制代碼 代碼如下:

>>> print list(itertools.permutations([1,2,3,4],2))
[(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]

無序組合:e.g.,4個數(shù)內(nèi)選2個:
復制代碼 代碼如下:

>>> print list(itertools.combinations([1,2,3,4],2))
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]

相關文章

最新評論