This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
import time | |
import random | |
number_list = [] | |
def sub_process(i, number): | |
rand = random.random() | |
time.sleep(rand) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def two_sum(number_list,target): | |
hash_dict = dict() | |
for key,value in enumerate(number_list): | |
hash_dict.update({value: key}) | |
for i, number in enumerate(number_list): | |
j = hash_dict.get(target - number) | |
if j is not None and j != i: | |
return [i,j] | |