I am writing a program that has to work through roughly 1000 candidates and find the best score. I need to use multiprocessing to work through a list because this will be done roughly 60000 times. How would we use multiprocessing in this situation. Say that the score is calculated like this:
def get_score(a, b):
return (a * b) / (a + b)
I know a
in every case but it changes every time you go through the list of candidates because it adds the best candidate to the list. I want it to iterate through a list of candidates and then find the best score. A non-multiprocessing example would be like this:
s = [random.randint(0, 100)]
candidates = [random.randint(0, 100) for i in range(1000)]
for i in range(60000):
best_score = 0
best_candidate = candidates[0]
for j in candidates:
if get_score(s[-1], j) > best_score:
best_candidate = j
best_score = get_score(s[-1], j)
s.append(best_candidate)
I know that I could create a function but I feel like there is an easier way to do this. Sorry for the beginner question.:/