def read_numbers(filename): """ Reads a file of numbers, stores them in a list, and returns the list of numbers :param filename: (str) the name of the file that contains the numbers, one number per line :return: (list) the list that contains the file numbers """ file = open(filename, "r") numbers = [] for number in file: numbers.append(int(number)) file.close() return numbers def get_counts(data): """ Given a list, it creates a dictionary of frequency of list items :param data: (list) a list of items to create a frequency dictionary :return: (dict) a frequency dictionary that corresponds to the provided data """ counts = {} for val in data: if val in counts: counts[val] += 1 else: counts[val] = 1 return counts def print_counts(counts): """ Given a dictionary, it prints its key-value pairs :param counts: (dict) the dictionary to print :return: (None) """ for key in counts: print(str(key) + "\t" + str(counts[key])) def get_most_frequent_value(data): """ Given a list of numbers, it returns the number that appears the most times in the list :param data: (list) a list of numbers :return: (int) the number that appears the most times in the list """ counts = get_counts(data) 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(data): """ Given a list with numbers, it returns the number that appears the most times in the list along with its frequency :param data: (list) list of numbers to find the one with the highest frequency :return: (tuple) number-frequency tuple, where number is the one with the highest frequency in the list """ counts = get_counts(data) 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)