Skip to content

Commit

Permalink
2024-03-10 뉴스 클러스터링
Browse files Browse the repository at this point in the history
  • Loading branch information
kjs254 committed Mar 10, 2024
1 parent d9fc0fc commit c201d2f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kjs254/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
| 5차시 | 2024.02.24 | DFS | [모음사전](https://school.programmers.co.kr/learn/courses/30/lessons/84512) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/19) |
| 6차시 | 2024.02.27 | 스택 | [괄호 회전하기](https://school.programmers.co.kr/learn/courses/30/lessons/76502) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/22) |
| 7차시 | 2024.03.01 | 구현 | [캐시](https://school.programmers.co.kr/learn/courses/30/lessons/17680) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/24) |
=======
| 8차시 | 2024.03.08 | 구현 | [튜플](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/30) |
| 9차시 | 2024.03.08 | 구현 | [뉴스 클러스터링](https://school.programmers.co.kr/learn/courses/30/lessons/17677) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/33) |
---
39 changes: 39 additions & 0 deletions kjs254/구현/뉴스 클러스터링.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def MakeSet(s): #2글자씩 끊은 알파벳만 리스트로 출력
lst = []
for i,_ in enumerate(s[:-1]):
a = s[i:i+2]
if a.isalpha():
lst.append(a.lower())
return lst

def func(l1, l2): #중복 교집합과 중복 합집합의 길이를 각각 출력
intersection_set, union_set = [], []
inter = set(l1) & set(l2)
union = set(l1) | set(l2)

for n in union:
intersection_num = min(l1.count(n),l2.count(n))
union_num = max(l1.count(n),l2.count(n))

for _ in range(intersection_num):
intersection_set.append(n)

for _ in range(union_num):
union_set.append(n)

return len(intersection_set), len(union_set)

def solution(str1, str2): #메인 코드
answer = 0

arr1 = MakeSet(str1)
arr2 = MakeSet(str2)

a,b = func(arr1,arr2)

if b:
answer = int((a/b)*65536)
else:
answer = 65536

return answer

0 comments on commit c201d2f

Please sign in to comment.