Given a combination of k
of the first n
natural numbers, for some reason I need to find the position of such combination among those returned by
Looks like you need to better specify your task or I am just getting it wrong. For me it seems that when you iterating through the itertools.combination
you can save indexes you need to an appropriate data structure. If you need all of them then I would go with the dict
(one dict
for all your needs):
combinationToIdx = {}
for (idx, comb) in enumerate(itertools.combinations(range(1,14),6)):
combinationToIdx[comb] = idx
def findIdx(comb):
return combinationToIdx[comb]