itertools模塊

##chain## chain函數,連接多個可迭代對象。 from itertools import chain test = chain('AB', 'CDE', 'F') for el in test: print el函數

##combinations(iterable, r):## 建立一個迭代器,返回iterable中全部長度爲r的子序列,返回的子序列中的項按輸入iterable中的順序排序: from itertools import combinations test = combinations([1,2,3,4,5], 3) for el in test: print elcode

(1, 2, 3)
(1, 2, 4)
(1, 2, 5)
(1, 3, 4)
(1, 3, 5)
(1, 4, 5)
(2, 3, 4)
(2, 3, 5)
(2, 4, 5)
(3, 4, 5)

##repeat(object [,times]) 重複times次## a = repeat([1,2], 10) for i in a: print i對象

相關文章
相關標籤/搜索