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

python 排列組合之itertools

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

import itertools 

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

>>> 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個(gè)數(shù)內(nèi)選2個(gè):
復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評(píng)論