import string def read_numbers(filename): numbers = [] file = open(filename, "r") for number in file: numbers.append(int(number)) file.close() return numbers def get_counts(data): counts = {} for val in data: if val in counts: counts[val] += 1 else: counts[val] = 1 return counts def print_counts(counts): for key in counts: print(str(key) + "\t" + str(counts[key])) def get_most_frequent_value(counts): max_key = 0 max_value = -1 for key in counts: if counts[key] > max_value: max_key = key max_value = counts[key] return max_key def get_most_frequent(counts): max_key = 0 max_value = -1 for key in counts: if counts[key] > max_value: max_key = key max_value = counts[key] return (max_key, max_value) def count_words(filename): word_counts = {} file = open(filename, "r") for line in file: words = line.split() for raw_word in words: word = raw_word.strip(string.punctuation) if word in word_counts: word_counts[word] += 1 else: word_counts[word] = 1 return word_counts