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

sophu·2021년 5월 8일
0

algorithm

목록 보기
2/4

문제

나의 코드

def solution(str1, str2):
    str1, str2 = list(str1.lower()), list(str2.lower())
    common = 0
    added = 0
    
    def create(lst):
        sets = []
        for i in range(len(lst) - 1):
            sample = lst[i: i + 2]
            if ''.join(lst[i: i + 2]).isalpha():
                sets.append(lst[i: i + 2])
        return sets
    
    sets1 = create(str1)
    sets2 = create(str2)
    minn, maxx = sets1, sets2
    
    
    if len(sets1) != len(sets2):
        minn = min(sets1, sets2)
        maxx = max(sets1, sets2)
    
    lenminn, lenmaxx = len(minn), len(maxx)
    
    for s in range(len(minn)):
        if minn[s] in maxx:
            common += 1
            maxx.remove(minn[s])
            
    if lenminn == 0 and lenmaxx == 0:
        return 65536
    else: 
        return int(common * 65536 / (lenminn + lenmaxx - common))

마음에 안든다.. 진짜 하드코딩 했다.

profile
티스토리에서 벨로그로 블로그 이사 중 > https://sophuu.tistory.com/

0개의 댓글