Skip to main content
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
added 2 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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. So 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 totoo long. Hoping 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 pythonPython.

Thanks

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()

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. So 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 to long. 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.

Thanks

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()

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()

Generating words based on a list of letter [Python]letters

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. SoSo constraints are that there is a control letter which means that letter must be in the word, and you can't repeat any letters. EverythingEverything works but the running time is way to long. HopingHoping to get some feedback on how to cut down my running time in O-notation. AlsoAlso if you know the running times of the built in function that would be great. AlsoAlso comment if my code style is not what it should be for python.

Thanks

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()

Generating words based on a list of letter [Python]

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. So 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 to long. 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.

Thanks

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()

Generating words based on a list of letters

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. So 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 to long. 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.

Thanks

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()
Tweeted twitter.com/#!/StackCodeReview/status/237247053883908096
Source Link
Greg Brown
  • 185
  • 1
  • 1
  • 4
Loading