<jupyter_start><jupyter_text>Solution to: [Day 0: Mean, Median, and Mode](https://www.hackerrank.com/challenges/s10-basic-statistics/problem) Table of Contents<jupyter_code>%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')<jupyter_output><empty_output><jupyter_text>- Table of Contents    - Wiki definition    - Equations    - Mean    - Median    - Mode- Solution    - Imports    - Constants    - Input    - Measures of Central Tendency    - Scale function    - Main  Wiki definitionIn statistics, a central tendency (or measure of central tendency) is a central or typical value for a probability distribution.The most common measures of central tendency are the arithmetic mean, the median, and the mode. A middle tendency can be calculated for either a finite set of values or for a theoretical distribution, such as the normal distribution. Occasionally authors use central tendency to denote "the tendency of quantitative data to cluster around some central value."The central tendency of a distribution is typically contrasted with its dispersion or variability; dispersion and central tendency are the often characterized properties of distributions. Analysis may judge whether data has a strong or a weak central tendency based on its dispersion.  Equations  Mean\begin{equation}\Large\mu = \frac{\sum_{i=1}^{n}x_{i}}{n} \end{equation} Median$$\normalsize\mathrm{Med}(X) = \begin{cases}X[\frac{n}{2}] & \text{if n is even} \\\Large\frac{X[\frac{n-1}{2}] + X[\frac{n+1}{2}]}{2} & \text{if n is odd}\end{cases}$$ Mode\begin{equation}\normalsize\mathrm{Mode}(X) = \mathrm{max}(\mathrm{frequency})\end{equation}  Solution	- Print on separate lines (mean, median, mode)	- Scale of 1 decimal place	- With multiple mode values, select min.  Imports<jupyter_code>from collections import Counter  # used to count instances for mode
from typing import List, Tuple, Union<jupyter_output><empty_output><jupyter_text>Constants<jupyter_code>SCALE = 1	# scale refers to number of decimal places<jupyter_output><empty_output><jupyter_text>Input<jupyter_code>def get_input() -> Tuple[int, list]:
    """Returns tuple of input:
    n: int, length of list.
    nums: list, nums to use.
    """
    n = int(input())
    nums = sorted(int(num) for num in input().split())
    return (n, nums)<jupyter_output><empty_output><jupyter_text>Measures of Central Tendency<jupyter_code>def calc_mean(nums: List[int], n: int) -> Union[int, float]:
	"""Returns mean of nums list with n elements."""
	return format_scale( sum(nums) / n)
def calc_median(nums: List[int], n: int) -> Union[int, float]:
	"""Returns median of nums list with n elements."""
	mid, is_odd = divmod(len(nums), 2)
	if is_odd:
		median = nums[mid]
	else:
		median = calc_mean( nums[mid - 1: mid + 1], 2)
	return format_scale(median)
def calc_mode(nums: List[int], n: int) -> int:
	"""Returns mode of nums list.
	
	Uses auxiliary get_mode_ties func.
	"""
	def get_mode_ties(num_counts: dict, max_freq: int) -> int:
		"""Generator function to return contenders for mode in dict."""
		for num, count in num_counts.items():
			if count == max_freq:
				yield num


	num_counts = Counter(nums)
	max_freq = num_counts[ max( num_counts, key = num_counts.get)]

	return min(list(get_mode_ties(num_counts, max_freq)))<jupyter_output><empty_output><jupyter_text>Scale function<jupyter_code>def format_scale(num: Union[int, float]) -> float:
	"""Returns float number ."""
	if isinstance(num, int):
		return num
	return round(num, SCALE)<jupyter_output><empty_output><jupyter_text>Main<jupyter_code>def main():
	measure_central_tendency = (
		calc_mean,
		calc_median,
		calc_mode
	)
	n, nums = get_input()
	for measure in measure_central_tendency:
		print(measure(nums, n))
if __name__ == "__main__":
	main()<jupyter_output>10
64630 11735 14216 99233 14470 4978 73429 38120 51135 67060
43900.6
44627.5
4978
{'fraction_non_alphanumeric': 0.1151577327519877, 'fraction_numerical': 0.021287509617850732, 'mean_word_length': 5.037151702786378, 'pattern_counts': {'":': 1, '<': 28, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '336291', 'license': 'Apache-2.0', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1260, 'n_words': 391, 'path': 'statistics/10_days/01_day0mean,median,andmode.ipynb', 'repo_name': 'jaimiles23/hacker_rank', 'size': '3899'}