뉴스 클러스터링 - python(programmers)

참치돌고래·2021년 8월 30일
0

알고리즘

목록 보기
21/36
post-custom-banner

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

from itertools import combinations
def solution(str1, str2):
    answer = 0
    stack1=[]
    stack2=[]
    
    for i in range(1,len(str1)):
        tmp = ''
        if (str1[i].isalpha()) :
            if(str1[i-1].isalpha()):
                tmp = str1[i-1]  + str1[i]
                stack1.append(tmp.lower())
                
    for i in range(1,len(str2)):
        tmp = ''
        if (str2[i].isalpha()) :
            if(str2[i-1].isalpha()):
                tmp = str2[i-1]  + str2[i]
                stack2.append(tmp.lower())
    
    inter  = []
    cnt = 0 
    for i in stack1:
        if i in stack2:
            stack2.remove(i)
            cnt+=1
    
    total = len(stack1+stack2)
    if total == 0:
        return 65536
    
    
    return int(cnt/total * 65536)
profile
안녕하세요
post-custom-banner

0개의 댓글