Python - Get index of a combination

Viewed 815

I need to generate combination from "a" to "]]]]]]" for example, in order to it I use this python script which works well.

import itertools

DATA_ALPHA_NUM = 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&-
()@=+;/!%$\\'\",.<>*^{}#~_[]"
b = 10

for i in range(1,int(b)+1):
   for e in itertools.combinations(DATA_ALPHA_NUM,i): print(''.join(e))

But now I need to do the inverse, for exemple : if I give "1" to the new script it will output "a", if I give 90 it will ouput "]" etc.

I wrote several scripts which worked fine for less than 737191 combinations but they were not good after.

EDIT : someone write something like that then delete it post It was almost perfect ..

alphaNumList = list(DATA_ALPHA_NUM)
alphaNumList.insert(0, "")

result = ["".join(item) for item in 
itertools.islice(itertools.product(alphaNumList, repeat=6), 0,1)]
2 Answers
Related