# Will have one global list which will store the words that are valid. It will read the words from file and keep adding the words in. global_word_list = [] def add(word): dict_file = open("dict.txt", "a") dict_file.write(word + "\n") global_word_list.append(word) print " added to word list " + str(global_word_list.__contains__(word)) dict_file.close() global_word_list.sort() def remove(word): dict_file = open("dict.txt", "r") temp_file = open("temp.txt", "w") for line in dict_file: current_word = line[:len(line)-1] # removing the newline so that the word can be compared to the one in the file. if word != current_word: temp_file.write(line) else: 5 if global_word_list.__contains__(word): global_word_list.remove(word) else: print word + " is not in the dictionary." dict_file.close() temp_file.close() dict_file = open("dict.txt", "w") temp_file = open("temp.txt", "r") for line in temp_file: dict_file.write(line) dict_file.close() temp_file.close() def check(word): return global_word_list.__contains__(word) def initialize(): dict_file = open("dict.txt", "r") for line in dict_file: global_word_list.append(line[:len(line) - 1]) global_word_list.sort() dict_file.close()