-
[프로그래머스] 오픈채팅방 문제 파이썬(Python) 풀이Problem Solving/Programmers 2021. 10. 4. 17:55
https://programmers.co.kr/learn/courses/30/lessons/42888
def solution(record): temp = [] names = {} result = [] for r in record: cmd = r.split() if cmd[0] == "Enter": temp.append([cmd[1], '님이 들어왔습니다.']) names[cmd[1]] = cmd[2] elif cmd[0] == "Leave": temp.append([cmd[1], '님이 나갔습니다.']) else: names[cmd[1]] = cmd[2] for t in temp: result.append(names[t[0]] + t[1]) return result
문제 내용대로 구현하면 되는 문제이다.
이름의 변경 내용을 알아야 하기 때문에, names라는 딕셔너리를 선언하고,
uid 값을 키로 이름들을 저장했다.
'Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스] 소수 찾기(Level 2) 문제 파이썬(Python) 풀이 (0) 2021.10.11 [프로그래머스] 네트워크 문제 파이썬(Python) 풀이 (0) 2021.10.04 [프로그래머스] 소수찾기 (0) 2021.06.14