import sys
from collections import Counter
  
t = int(sys.stdin.readline())
num_list = []
for _ in range(t):
    num_list.append(int(sys.stdin.readline())) 

def mode(x):
    mode_dict = Counter(x)
    modes = mode_dict.most_common()
    if len(x) > 1 : 
        if modes[0][1] == modes[1][1]:
            mod = modes[1][0]
        else : 
            mod = modes[0][0]
    else : 
        mod = modes[0][0]
    
    return mod

print(round(sum(num_list) / len(num_list)))
num_list.sort()
print(num_list[len(num_list) // 2])
print(mode(num_list))
print(num_list[-1] - num_list[0])

- Counter()는 각 num에 대해 빈도수를 dict로 만들어줌

- most_common()은 배열안에 튜플 형식으로 최빈값부터 2번째로 자주 나오는 수.... 를 반환함

- 최빈값이 여러 개인 경우, key값이 작은 것부터 정렬해서 나타내줌.

- 따라서 문제에서는 두번째로 작은 값이므로 1번째 것을 가져오면 됨

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 1978번(python)  (0) 2019.05.31
백준 1181번(python)  (0) 2019.05.30
백준 1427번(python)  (0) 2019.05.29
백준 2751번(python)  (0) 2019.05.29
백준 2750번(python)  (0) 2019.05.29