본문 바로가기

알고리즘

프로그래머스 튜플 - 2019 카카오 개발자 겨울 인턴십 (파이썬)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def solution(s):
    answer = []
    overlap_dict = dict()
    s_list = s[1:-1].split("},")
    for i in range(len(s_list)):
        s_list[i] = s_list[i].replace("}""").replace("{""")
        s_list[i] = s_list[i].split(",")
    for i in s_list:
        for j in i:
            if overlap_dict.get(j): overlap_dict[j] += 1
            else: overlap_dict[j] = 1
    sorted_overlap_dict = sorted(overlap_dict.items(), key= lambda x : x[1], reverse=True)
    for i in sorted_overlap_dict: answer.append(i[0])
    answer = list(map(int, answer))
    return answer
cs