반응형
Notice
Recent Posts
Recent Comments
Link
동캄의 코딩도장
프로그래머스 level2 [오픈채팅방] 파이썬 본문
반응형
https://programmers.co.kr/learn/courses/30/lessons/42888
코딩테스트 연습 - 오픈채팅방
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오
programmers.co.kr
#프로그래머스 오픈채팅방
def solution(record):
answer = []
lst={}
prompt=[]
for line in record:
s=list(map(str,line.split()))
if s[0]!='Leave':
lst[s[1]]=s[2]
prompt.append(s)
for line in prompt:
if line[0]=='Enter':
answer.append("{}님이 들어왔습니다.".format(lst[line[1]]))
elif line[0]=='Leave':
answer.append("{}님이 나갔습니다.".format(lst[line[1]]))
return answer
앞의 for문을 통해 최종 아이디와 이름을 매칭시킨다.
다음 for문을 통해 메세지를 생성한다.
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [전화번호 목록] 파이썬 (0) | 2021.12.11 |
---|---|
프로그래머스 level2 [더 맵게] 파이썬 (0) | 2021.12.11 |
프로그래머스 level2 [위장] 파이썬 (0) | 2021.12.10 |
프로그래머스 level2 [카펫] 파이썬 (0) | 2021.12.10 |
프로그래머스 level2 [문자열 압축] 파이썬 (0) | 2021.12.09 |