====== [1차] 뉴스 클러스터링 ====== ===== 풀이 ===== * 그냥 시키는대로 구현하면 되는 문제 * 파이썬에서는 collections.Counter을 다중집합처럼 사용할수 있다. 교집합과 합집합도 쉽게 구할 수 있다. python 3.10 이상에서는 원소의 총 갯수도 바로 구할수 있는 total() 메소드도 제공하지만, 프로그래머스에서는 아직 지원하지 않아서 그냥 sum으로 구했다. ===== 코드 ===== """Solution code for "Programmers 17677. [1차] 뉴스 클러스터링". - Problem link: https://programmers.co.kr/learn/courses/30/lessons/17677 - Solution link: http://www.teferi.net/ps/problems/programmers/17677 """ import collections MULTIPLIER = 65536 def solution(str1, str2): str1, str2 = str1.upper(), str2.upper() counter1 = collections.Counter( x + y for x, y in zip(str1, str1[1:]) if (x + y).isalpha()) counter2 = collections.Counter( x + y for x, y in zip(str2, str2[1:]) if (x + y).isalpha()) intersection = sum((counter1 & counter2).values()) union = sum((counter1 | counter2).values()) return MULTIPLIER if union == 0 else MULTIPLIER * intersection // union {{tag>프로그래머스 ps:problems:programmers:Level_2}}