1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import sys
from collections import deque, Counter
result = deque()
T = int(sys.stdin.readline().rstrip())
for _ in range(T):
result.append(int(sys.stdin.readline().rstrip()))
result = sorted(result)
def Am():
return round(sum(result)/T)
def Me():
return result[int(T//2)]
def Mo():
MoResult = Counter(result).most_common() # MoResult = [(-2, 1), (1, 1), (2, 1), (3, 1), (8, 1)]
if len(MoResult) > 1:
if MoResult[0][1] == MoResult[1][1]:
return MoResult[1][0]
else:
return MoResult[0][0]
else:
return MoResult[0][0]
def Ra():
return result[-1] - result[0]
print(Am())
print(Me())
print(Mo())
print(Ra())
# Counter 함수와 더 익숙해지면 좋을 것 같다.
# ex)
# from collections import Counter
# MoResult = Counter([7, 1, 2, 5, 1, 8, 7, 6]).most_common()
# print(MoResult) # [(7, 2), (1, 2), (2, 1), (5, 1), (8, 1), (6, 1)]
# .most_common()
# 입력된 인자들의 '순서'를 존중하면서, '중복 count해줌'과 동시에 '중복 삭제'까지 진행.
|