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 'product ='부분에서 의미합니까? –
@IanDimitri 예 또는'usedAtoms'의 정의에 있습니다. –