[프로그래머스]1차 뉴스 클러스터링

진경·2022년 6월 28일
0

코딩테스트 준비

목록 보기
7/18
post-custom-banner

https://programmers.co.kr/learn/courses/30/lessons/17677

from collections import Counter
def solution(str1, str2):
    arr1=[]
    arr2=[]
    for i in range(0,len(str1)-1):
        if(str1[i].isalpha() and str1[i+1].isalpha()):
            arr1.append(str1[i].lower()+str1[i+1].lower())
    for i in range(0,len(str2)-1):
         if(str2[i].isalpha() and str2[i+1].isalpha()):
            arr2.append(str2[i].lower()+str2[i+1].lower())
    if not arr1 and not arr2:
        return 65536
    arr1=Counter(arr1)
    arr2=Counter(arr2)
    inter = list((arr1 & arr2).elements())
    union = list((arr1 | arr2).elements())
    answer=len(inter)/len(union)
    return int(answer*65536)

from collections import Counter
Counter와 elements()
https://dongdongfather.tistory.com/70

profile
프론트엔드 취준생입니다
post-custom-banner

0개의 댓글