""" count_words.py count the words in a file in class """ def readfile(filename = 'words.txt'): """ return list of words from file """ the_file = open(filename, 'r') lines = the_file.readlines() words = [] for line in lines: words.append(line.strip()) return words def countwords(wordlist): """ return dictionary of {word:count} """ counts = {} for word in wordlist: if word in counts: counts[word] = 1 + counts[word] else: counts[word] = 1 return counts def main(): words = readfile() print(words) main()