Для вашего первого вопроса я предлагаю вам посмотреть здесь на верхние ответы, чтобы увидеть, как распараллелить for l oop, который я описываю ниже (который отвечает на вопрос 2): простой Python l oop?
Второй вопрос:
#dummy function for illustrative purposes
def function(a,b,c,d,e,f,g,h):
return a+b+c+d+e+f+g+h
Если бы вывод функций был хешируемым, я бы создал словарь:
#This is your 'objects'
O={}
for y in range(2**8):
#this generates all the permutations you were after I believe
s=format(y, '#010b')[2:]
#print(s) #uncomment to see what it does
#This is slightly messy, in that you have to split up your integer into its components, but I've seen worse.
O[y]=function(int(s[0]),int(s[1]),int(s[2]),int(s[3]),int(s[4]),int(s[5]),int(s[6]),int(s[7]))
#Now, if you wanted to print the output of f(1,1,1,1,1,1,1,1):
g='11111111'
print(O[int(g,2)]) #uncomment to see what it does
#print(O) #uncomment to see what it does
Если вывод не может быть хеширован, просто оставьте список:
O=[]
for y in range(2**8):
#this generates all the permutations you were after I believe
s=format(y, '#010b')[2:]
#print(s) #uncomment to see what it does
#This is slightly messy, in that you have to split up your integer into its components, but I've seen worse.
O.append(function(int(s[0]),int(s[1]),int(s[2]),int(s[3]),int(s[4]),int(s[5]),int(s[6]),int(s[7])))
#Now, if you wanted to print the output of f(1,1,1,1,1,1,1,1):
g='11111111'
#print(O[int(g,2)]) #uncomment to see what it does
#print(O) #uncomment to see what it does