문제
def solution(str1, str2):
str1 = str1.upper()
str2 = str2.upper()
str1_dic = dict()
str2_dic = dict()
ing = set([s for s in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
for idx in range(len(str1)-1):
key = str1[idx:idx+2]
if key[0] not in ing or key[1] not in ing:
continue
if key not in str1_dic.keys():
str1_dic[key] = 1
else:
str1_dic[key] += 1
for idx in range(len(str2)-1):
key = str2[idx:idx+2]
if key[0] not in ing or key[1] not in ing:
continue
if key not in str2_dic.keys():
str2_dic[key] = 1
else:
str2_dic[key] += 1
inter = 0
union = 0
for key in set(list(str1_dic.keys())+list(str2_dic.keys())):
if key in str1_dic.keys() and key in str2_dic.keys():
inter += min(str1_dic[key], str2_dic[key])
union += max(str1_dic[key], str2_dic[key])
elif key in str1_dic.keys() and key not in str2_dic.keys():
union += str1_dic[key]
else:
union += str2_dic[key]
if union == 0:
answer = 1*65536
else:
answer = int((inter / union) * 65536)
return answer