출처 : 프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/42888
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
더보기
풀이
from collections import defaultdict
def solution(record):
answer = []
nickname_list = defaultdict(lambda x: '')
log_list = []
for rec in record:
act, *information = rec.split()
if act == 'Enter' or act == 'Change':
nickname_list[information[0]] = information[1]
if act == 'Enter' or act == 'Leave':
log_list.append([act, information[0]])
for log in log_list:
act, user = log
if act == 'Enter':
answer.append(nickname_list[user] + '님이 들어왔습니다.')
else:
answer.append(nickname_list[user] + '님이 나갔습니다.')
return answer
유저의 닉네임이 바뀌어도 유저의 로그는 표시해야하기 때문에
유저의 닉네임과 유저의 로그를 별도로 구분해서 나중에 최종 닉네임으로 합치는게 편하다.
Github
GitHub - bh2980/Algorithm-Problem: 알고리즘 풀이 흔적들
알고리즘 풀이 흔적들. Contribute to bh2980/Algorithm-Problem development by creating an account on GitHub.
github.com
'알고리즘 > Python' 카테고리의 다른 글
[python] 프로그래머스 - 괄호 변환 (0) | 2023.03.10 |
---|---|
[python] 프로그래머스 - 메뉴 리뉴얼 (0) | 2023.03.10 |
[python] 프로그래머스 - k진수에서 소수 개수 구하기 (0) | 2023.03.09 |
[python] 프로그래머스 - 튜플 (0) | 2023.03.09 |
[python] 프로그래머스 - 멀리 뛰기 (1) | 2023.03.09 |