/mode-calculator

calculate the mode of a set of numbers

Primary LanguagePythonBSD 2-Clause "Simplified" LicenseBSD-2-Clause

mode_calculator

ModeCounter Objects

class ModeCounter()

Class to keep track of the mode in a list of numbers.

Attributes:

  • frequency_dictionary - A dictionary where keys are numbers and values are their frequency
  • winning_frequency - The highest frequency among all numbers.
  • winner - The number with the highest frequency.

__init__

def __init__()

Initializes frequency dictionary and sets winning_frequency to 0

add_number

def add_number(number)

Adds a number to the frequecny dictionary and update the mode.

Arguments:

  • number - The number to be added.

update

def update(number)

Updates the current mode if the frequency of the number is higher than the current modes frequency.

args: number: The number to be checked against the current mode.

get

def get()

Returns the winner

Returns:

The number with the highest frequency.