2
我怎麼會去從字典中的元組給定的範圍爲這個字典創建所有可能組合的字典中的所有可能的組合?如何從使用範圍,每個值
def createCombo(self):
usedAtoms = {'C':(0,100),'H':(0,200),'O':(0,4),'N':(0,4),'S':(0,4)}
MolecularFormula.combinations(self, usedAtoms)
def combinations(self,dicts):
product = [x for x in apply(itertools.product, dicts.values())]
print [dict(zip(dicts.keys(), p)) for p in product]
就快,只需用'range'功能上的每一對。 –
@AlexHall是否指「產品=」部分? –
@IanDimitri yes,或者在'usedAtoms'的定義中。 –