Beakjoon&프로그래머스/파이썬

[프로그래머스/파이썬] 튜플

현장 2022. 5. 17. 20:19

-Code

def solution(s):
    answer = []
    li = sorted(list(s[2:-2].split("},{")), key=lambda x: len(x))

    for a in li:
        a = a.split(',')
        for b in a:
            b = int(b)
            if b not in answer:
                answer.append(b)

    return answer

처음에는 stack을 이용해 풀려했으나 출력하는 리스트가 계속 정렬이 되어서 다른 방법을 찾았습니다. split을 이용하니 더 쉽게 만들어져서 해결을 했습니다.