所以这就是我到目前为止:
def createCombo(self):
usedAtoms = {'C':(0,101),'H':(0,201),'O':(0,4),'N':(0,4),'S':(0,4)}
MolecularFormula.combinations(self, usedAtoms)
def combinations(self,dicts):
product = [x for x in itertools.product(*[range(*x) for x in dicts.values()])]
print product
##print [dict(zip(dicts.keys(), p)) for p in product],
它最终打印出这样的东西:
[(0, 0, 0, 0, 0), (0, 0, 0, 0, 1), (0, 0, 0, 0, 2), (0, 0, 0, 0, 3), (0, 0, 0, 1, 0), (0, 0, 0, 1, 1), (0, 0, 0, 1, 2), (0, 0, 0, 1, 3), (0, 0, 0, 2, 0), (0, 0, 0, 2, 1)
这就是我想要打印出来的内容,但是如何在其中一种产品中获取某个索引?
如果我想要从中获取3:(0,0,0,0,3)
答案 0 :(得分:0)
{{1}}