I'm trying to create a program that reads a txt file and gives me an output of the number of times a word of length x (lets say 5) or longer is used. For example, the txt has "The quick brown fox jumps over the lazy dog", The expected out put is 3. I created a function that finds the number of occurrences of a certain word and the number of words in the file but I don't know how to do this. Thanks
def engr102_word_count(): num_words = 0 with open(name, 'r') as x: for line in x: words = line.split() num_words += len(words) x.close() file1= open(name, 'r') str_list = file1.read() count = 0 N = len(str_list) n = len(word) for i in range(0,N-n): if str_list[i:i + n] == word: count += 1 print("Number of words: ", num_words) print("Frequency of your word: ", count)