2014-06-13 39 views
1

我有可能的點[0,1,2]。我怎麼可以列出所有可能的方式來從樣品清單0-10的分數滿分爲5分變成列表的可能結果

例如:

score 0: score 0,0,0,0,0 
score 1: score 00001, 00010, 00100, 01000, 10000 .... 
... 
... 

不是真的知道如何處理這個問題

我覺得這是一個置換問題,我產生使用set 0,1 5個號碼的排列,2

+0

創造分數0 - 10?爲什麼10? – mgilson

+0

因爲2,2,2,2,2加起來最多爲10 – Liondancer

回答

0
import itertools 

combns = list(itertools.combinations_with_replacement([0,1,2],5)) 

comb_dict = {} 
for combn in combns: 
    value = sum(combn) 
    permuts = list(itertools.permutations(combn)) 
    permuts = list(set(permuts)) 
    print type(permuts) 
    if value in comb_dict: 
     comb_dict[value].extend(permuts) 
    else: 
     comb_dict[value] = permuts 

現在comb_dict與鍵0-10和值其是對應於所有的獨特組合/排列的元組的列表的字典。