I wrote a program to take a list of letters and from every permutation of them and check that against the dictionary and print out valid words. The constraints are that there is a control letter which means that letter must be in the word, and you can't repeat any letters.
Everything works, but the running time is way too long. I'm hoping to get some feedback on how to cut down my running time in O-notation. Also, if you know the running times of the built in function, that would be great. Also, comment if my code style is not what it should be for Python.
import itertools from multiprocessing import Process, Manager dictionary_file = '/usr/share/dict/words' letter_list = ['t','b','a','n','e','a','c','r','o'] control_letter = 'e' manager = Manager() word_list = manager.list() def new_combination(i, dictionary): comb_list = itertools.permutations(letter_list,i) for item in comb_list: item = ''.join(item) if(item in dictionary): word_list.append(item) return def make_dictionary(): my_list =  dicts = open(dictionary_file).readlines() for word in dicts: if control_letter in word: if(len(word) >3 and len(word)<10): word = word.strip('\n') my_list.append(word) return my_list def main(): dictionary = make_dictionary() all_processes =  for j in range(9,10): new_combo = Process(target = new_combination, args = (j,dictionary,)) new_combo.start() all_processes.append(new_combo) while(all_processes): for proc in all_processes: if not proc.is_alive(): proc.join() all_processes = [proc for proc in all_processes if proc.is_alive()] if(len(all_processes) == 0): all_processes = None print list(set(word_list)) if __name__ == '__main__': main()