[Python] 연습

[python] 프로그래머스 성격유형검사하기

Simon Yoon 2022. 10. 28. 23:15
def solution(survey, choices):
    answer = ''

    char_dict = {'R': 0, 'T': 0,
                 'C': 0, 'F': 0,
                 'J': 0, 'M': 0,
                 'A': 0, 'N': 0}
    # -> use defaultdict(int)

    score_dict = {1: 3, 2: 2, 3: 1,
                  4: 0,
                  5: 1, 6: 2, 7: 3}

    # 1~3 비동의, 4 모름, 5~7 동의
    for i in range(len(choices)):
        if choices[i] < 4:
            char_dict[survey[i][0]] += score_dict[choices[i]]
        elif choices[i] > 4:
            char_dict[survey[i][1]] += score_dict[choices[i]]
    print(char_dict)

    # 결과 확인
    for i in range(0, 7, 2):
        if char_dict[list(char_dict.keys())[i]] >= char_dict[list(char_dict.keys())[i+1]]:
            answer += list(char_dict.keys())[i]
        else:
            answer += list(char_dict.keys())[i+1]
    print(answer)

    return answer