Skip to content

Commit 5ab39a7

Browse files
committed
01 뉴스 클러스터링
1 parent 9334312 commit 5ab39a7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
File renamed without changes.

뉴스 클러스터링/sehwa.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
def input_str(raw_str):
2+
'''
3+
자카드 유사도를 측정하기 위해, 갈무리된 형태로 변형
4+
'''
5+
str = []
6+
for index in range(len(raw_str)-1):
7+
raw_str = raw_str.lower()
8+
if raw_str[index:index+2].isalpha():
9+
str.append(raw_str[index:index+2])
10+
11+
return str
12+
13+
14+
def jaccard_similarity(str1, str2):
15+
'''
16+
자카드 유사도 판별
17+
'''
18+
if not str1 and not str2 :
19+
return 1
20+
21+
intersec = str1+str2
22+
union = str1+str2
23+
for char in str1 :
24+
if char in str2:
25+
union.remove(char)
26+
str2.remove(char)
27+
28+
intersec = len(intersec) - len(union)
29+
30+
return intersec / len(union)
31+
32+
33+
def solution(str1, str2):
34+
35+
answer = int(jaccard_similarity(input_str(str1), input_str(str2)) * 65536)
36+
37+
return answer
38+
39+
40+
41+
# 테스트 1 〉 통과 (0.02ms, 10.3MB)
42+
# 테스트 2 〉 통과 (0.03ms, 10.3MB)
43+
# 테스트 3 〉 통과 (0.02ms, 10.3MB)
44+
# 테스트 4 〉 통과 (1.99ms, 10.3MB)
45+
# 테스트 5 〉 통과 (0.03ms, 10.2MB)
46+
# 테스트 6 〉 통과 (0.02ms, 10.3MB)
47+
# 테스트 7 〉 통과 (0.08ms, 10.3MB)
48+
# 테스트 8 〉 통과 (0.02ms, 10.3MB)
49+
# 테스트 9 〉 통과 (0.07ms, 10.3MB)
50+
# 테스트 10 〉 통과 (0.17ms, 10.4MB)
51+
# 테스트 11 〉 통과 (0.34ms, 10.2MB)
52+
# 테스트 12 〉 통과 (0.01ms, 10.2MB)
53+
# 테스트 13 〉 통과 (0.07ms, 10.3MB)

0 commit comments

Comments
 (0)