You are viewing a single comment's thread. Return to all comments →
from collections import Counter n=int(input()) arr=list(map(int,input().split())) mean=sum(arr)/n freq=Counter(arr) sorted_dict = { k: v for k, v in sorted(freq.items(), key=lambda item: (-item[1], item[0])) } mode,*_=sorted_dict arr=sorted(arr) if n%2==0: median=(arr[n//2]+arr[(n//2)-1])/2 else: median=arr[(n//2)-1] print(mean) print(median) print(mode)
or
import statistics from collections import Counter n = int(input()) arr = list(map(int, input().split())) mean = statistics.mean(arr) median = statistics.median(arr) freq=Counter(arr) mode = max(freq.items(), key=lambda item: (item[1], -item[0]))[0] print(f"{mean:.1f}") print(f"{median:.1f}") print(mode)
Seems like cookies are disabled on this browser, please enable them to open this website
Day 0: Mean, Median, and Mode
You are viewing a single comment's thread. Return to all comments →
or