Skip to content

Commit 7ff67f5

Browse files
committed
[PGS] 뉴스클러스터링 / Level 2 / 55분 (성공)
1 parent 2fdb5bd commit 7ff67f5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from collections import Counter
2+
3+
def solution(str1, str2):
4+
answer = 0
5+
A = [] # str1
6+
B = [] # str2
7+
8+
# str1과 str2 전처리: 2개씩 끊어서 저장하기
9+
for i in range(len(str1)):
10+
temp = str1[i:i+2].lower() # 대소문자 구분 X
11+
if temp.isalpha() and len(temp) == 2:
12+
A.append(temp)
13+
14+
for i in range(len(str2)):
15+
temp = str2[i:i+2].lower() # 대소문자 구분 X
16+
if temp.isalpha() and len(temp) == 2:
17+
B.append(temp)
18+
19+
# Counter 객체로 변환
20+
A = Counter(A)
21+
B = Counter(B)
22+
23+
# 교집합과 합집합 구하기
24+
intersection = A & B
25+
union = A | B
26+
27+
# 합집합의 수가 0인 경우에 대한 예외처리
28+
if sum(union.values()) == 0:
29+
answer = 65536
30+
else:
31+
answer = int(sum(intersection.values()) / sum(union.values()) * 65536)
32+
33+
return answer
34+

0 commit comments

Comments
 (0)