I have a function that iterates over a list of tuples (both integers) and checks if both integers exist in another list that contains integers (no tuples). If the key already exists, increment the value by one; otherwise, add the key and set the value equal to one:
def counts(double_int_list, single_int_list, dictionary_counts):
for double_int in double_int_list:
int1 = double_int[0]
int2 = double_int[1]
if int1 in single_int_list and int2 in single_int_list:
if not dictionary_counts: # if dict is empty
dictionary_counts[double_int] = 1
elif double_int in combination_counts.keys(): # if key already exists
dictionary_counts[double_int] += 1
else: # if key does not exist
dictionary_counts[double_int] = 1
My goal is to use the multiprocessing
module to speed this up (there are at least 4 million double integers, more in the future). I will be looping over this function multiple times, where the double_int_list
remains the same but the single_int_list
changes over every iteration.
I've attempted looking this up and found only one post that was relevant but there was no final answer. I have found answers to my issue of multiple arguments (can't use map
directly since I have one iterable argument and one constant argument) and dealing with writing to the same dictionary (possibly multiprocessing.Queue()
, Manger()
, Lock()
, and/or SyncManager()
). But, I'm very new to multiprocessing and I'm having a hard time putting everything together. It's possible that this type of function may not be able to be split or save much time but any advice/suggestions/comments is appreciated! If more information is needed, let me know.