def is_word_in_file(word, filename): dictionary = dict() for line in generate_cleaned_lines(filename): list_of_line_words = line.lower().split() for word in list_of_line_words: dictionary[word] = dictionary.get(word, 0) + 1 print(dictionary)
def is_word_in_file(word, filename): for line in generate_cleaned_lines(filename): list_of_line_words = line.lower() if word in line: print("The document " + filename + " contains the word " + word + ".") exit() print("The document " + filename + " does not contain the word " + word + ".")
def is_word_in_file(word, filename): count = 0 for line in generate_cleaned_lines(filename): # line will be a string of each line of the file in order # Your code goes here. # Your code should do something with the word and line variables and assign the value to a variable for returning if line.find(word) > 0: count = count + 1 return count
def is_word_in_file(word, filename): line_number = 0 lines_of_found_word = [] for line in generate_cleaned_lines(filename): line_number += 1 line = line.lower() if word in line: lines_of_found_word.append(line) if lines_of_found_word == []: print("The document " + filename + " does not contain the word " + word + ".") else print("The document " + filename + " contains the word " + word + ".") print("It can be found on lines: " + ", ".join(str(line_num) for line_num in lines_of_found_word))
def is_word_in_file(word, filename): i = 0 lines_found = [] for line in generate_cleaned_lines(filename): i += 1 # line will be a string of each line of the file in order # Your code goes here. Do something with the word and line variables if word in line: lines_found.append(i) # result = 'that word was found on line {0}'.format(i) if len(lines_found) > 0: print 'your word was found on these lines:' print lines_found print 'total number of lines that word was found on: {0}'.format(len(lines_found)) else: print 'your word was not found :('
def is_word_in_file(word, filename): for line in generate_cleaned_lines(filename):