Programming/Programmers
[프로그래머스] 오픈채팅방(Python)
데이터현
2021. 10. 22. 00:53
https://programmers.co.kr/learn/courses/30/lessons/42888
코딩테스트 연습 - 오픈채팅방
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오
programmers.co.kr
나의 코드
def solution(record):
user = dict()
answer= []
for i in record:
info = i.split()
if info[0] =='Enter' or info[0]=='Change':
user[info[1]]=info[2]
for i in record:
info = i.split()
if info[0] =='Enter':
chat = f'{user[info[1]]}님이 들어왔습니다.'
answer.append(chat)
elif info[0] =='Leave':
chat = f'{user[info[1]]}님이 나갔습니다.'
answer.append(chat)
return answer
dict에 회원 정보를 저장해 놓고 입장 혹은 변경할 때 id와 닉네임 값을 저장해 주면 된다.