Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_word(dict_file, the_word):
- ''' Searches through a text file for occurences of a given word
- The function goes through the file line by line, putting all words of the line into a list.
- It then checks if said word is in the list and adds (line_number, line_string) to the output.
- Input: (file_path, word_you're_searching_for)
- '''
- found_it = False
- # does one iteration too much but whatever .. :3
- while found_it == False and dict_file.tell() < 28956000: # 2nd condition = end of file
- current_line = dict_file.readline()
- altered_current_line = current_line
- for i in ["'", "`", "(", ")", "[", "]", "{", "}",
- ":", ",", ".", "!", "?", '"', ";"]:
- if i in altered_current_line:
- altered_current_line = altered_current_line.replace(i, " ")
- current_word_list = altered_current_line.split()
- if the_word in current_word_list:
- found_it = True
- dict_file.seek(dict_file.tell() - len(current_line) - 1)
- return None
- def webster_definition(unclear_word):
- dict_file = open("webster.txt", "r")
- dict_file.seek(550)
- find_word(dict_file, unclear_word.upper())
- find_word(dict_file, "Defn")
- dict_file.seek(dict_file.tell() + 6)
- # Fraidy: Paragraph stuff start ---------------------
- start = dict_file.tell()
- length = 5
- stopper = 0
- while length > 1 and stopper < 20:
- length = len(dict_file.readline())
- stopper += 1
- end = dict_file.tell()
- dict_file.seek(start)
- result = dict_file.read(end - start - stopper)
- dict_file.close()
- return result
- print webster_definition("axstone")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement