I have something like the following:
d = {...} #a dictionary with strings
l1 = [...] #a list with stuff
l2 = [...] #a list with numbers
...
for i in l1:
for key in l2:
#do some stuff
...
if d[key] == i:
print d[key]
and I would like to do the same using threads (for performance improvement). I am thinking in something like:
import threading
d = {...} #a dictionary with strings
l1 = [...] #a list with stuff
l2 = [...] #a list with numbers
...
def test(i, key):
#do the same stuff
if d[key] == i:
print d[j]
for i in l1:
for key in l2:
threading.start_new_thread(test, (i,key))
I'm not sure wether this is the best approach. My greates fear is that I am not optimizing at all. Some fundamental ideas are:
- d should be in shared memory (it can be accessed by all threads). I assume that no thread will access the same entry.
- Every (i, key) combinations should be being tested at the same time.
If in your opinion I should use another language, I would be glad if you could point it out. Help would be vey apreciated. Thanks in advance.