NeroCube / bookmark

Place some learning resources
0 stars 0 forks source link

Python 排列組合範例 #296

Open NeroCube opened 3 years ago

NeroCube commented 3 years ago

Example

from itertools import combinations
cols = list(range(1, 15+1))
num = 0
for c in range(10,len(cols)+1):
    print(c)
    print('-'*10)
    for selected_feature in list(combinations(cols,c)):
        print(list(selected_feature))
        num=num+1
print(num)

Reference

itertools --- 為高效循環而創建迭代器的函數