File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ from collections import Counter
2+
3+ def solution (str1 , str2 ):
4+ answer = 0
5+ A = [] # str1
6+ B = [] # str2
7+
8+ # str1과 str2 전처리: 2개씩 끊어서 저장하기
9+ for i in range (len (str1 )):
10+ temp = str1 [i :i + 2 ].lower () # 대소문자 구분 X
11+ if temp .isalpha () and len (temp ) == 2 :
12+ A .append (temp )
13+
14+ for i in range (len (str2 )):
15+ temp = str2 [i :i + 2 ].lower () # 대소문자 구분 X
16+ if temp .isalpha () and len (temp ) == 2 :
17+ B .append (temp )
18+
19+ # Counter 객체로 변환
20+ A = Counter (A )
21+ B = Counter (B )
22+
23+ # 교집합과 합집합 구하기
24+ intersection = A & B
25+ union = A | B
26+
27+ # 합집합의 수가 0인 경우에 대한 예외처리
28+ if sum (union .values ()) == 0 :
29+ answer = 65536
30+ else :
31+ answer = int (sum (intersection .values ()) / sum (union .values ()) * 65536 )
32+
33+ return answer
34+
You can’t perform that action at this time.
0 commit comments