알고리즘/Programmers
파이썬 | 프로그래머스 | 오픈채팅방
cha-n
2021. 5. 19. 12:09
def solution(record):
answer = []
# 동작
act = dict()
act["Enter"] = 1
act["Leave"] = 2
# 닉네임
nickname = dict()
history = []
for i in range(len(record)):
temp = record[i].split(" ")
if temp[0]=="Enter":
history.append((act.get(temp[0]), temp[1]))
nickname[temp[1]] = temp[2]
elif temp[0]=="Leave":
history.append((act.get(temp[0]), temp[1]))
else:
nickname[temp[1]] = temp[2]
result = []
for i in range(len(history)):
if history[i][0]==1:
answer.append(nickname.get(history[i][1])+"님이 들어왔습니다.")
else:
answer.append(nickname.get(history[i][1]) + "님이 나갔습니다.")
return answer
Enter를 1, Leave를 2로 저장했는데 굳이...? 싶다..
https://programmers.co.kr/learn/courses/30/lessons/42888