문제링크: 뉴스 클러스터링
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️ |
| 풀이시간 | 18분 |
| 제출횟수 | 3 |
| 인터넷검색유무 | yes |
🍒 My Code
def solution(str1, str2):
str1 = str1.lower()
str2 = str2.lower()
answer = 0
one,two = [],[]
for i in range(len(str1)-1):
if str1[i:i+2].isalpha():
one.append(str1[i:i+2])
for i in range(len(str2)-1):
if str2[i:i+2].isalpha():
two.append(str2[i:i+2])
summ,same=len(one)+len(two),0 #summ:합집합, same:교집합
for i in one:
if i in two:
same+=1
two.remove(i)
return 65536 if summ==0 else int((same/(summ-same))*65536)
💡 What I learned
문자열 구성이 알파벳인지 확인: str.isalpha()new_list = [value for value in org_list if value != "지우고싶은 값"]
import re
import math
def solution(str1, str2):
str1 = [str1[i:i+2].lower() for i in range(len(str1)-1) if str1[i:i+2].isalpha()]
str2 = [str2[i:i+2].lower() for i in range(len(str2)-1) if str2[i:i+2].isalpha()]
gyo = set(str1) & set(str2)
hap = set(str1) | set(str2)
if len(hap) == 0 :
return 65536
gyo_sum = sum([min(str1.count(gg), str2.count(gg)) for gg in gyo])
hap_sum = sum([max(str1.count(hh), str2.count(hh)) for hh in hap])
return math.floor((gyo_sum/hap_sum)*65536)