[python]ํ๋ก๊ทธ๋๋จธ์ค - ์คํ์ฑํ ๋ฐฉ
https://school.programmers.co.kr/learn/courses/30/lessons/42888
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
def solution(record):
answer=[]
actions = []
userDb= {}
for r in record:
#๋์ด์ฐ๊ธฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ๋๋๊ธฐ
temp = r.split()
state,userId = temp[0],temp[1]
#๋๋ค์ ๋ฐ๋ ๋์ ๋ค์ ๋ค์ด์ฌ ๋ ์ด๋ฆ ๋ฐ๋๊ฒ dictionary ์ฌ์ฉ
if state in ('Enter','Change'):
nickname = temp[2]
userDb[userId] = nickname
actions.append((state,userId))
for a in actions:
state,nick = a[0],a[1]
if state == 'Enter':
answer.append(f'{userDb[nick]}๋์ด ๋ค์ด์์ต๋๋ค.')
elif state == 'Leave':
answer.append(f'{userDb[nick]}๋์ด ๋๊ฐ์ต๋๋ค.')
return answer
'Problem Solving > PROGRAMMERS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python]ํ๋ก๊ทธ๋๋จธ์ค - ๋ด์ค ํด๋ฌ์คํฐ๋ง (0) | 2022.08.01 |
---|---|
[python]ํ๋ก๊ทธ๋๋จธ์ค - ํํ (0) | 2022.08.01 |
[python]ํ๋ก๊ทธ๋๋จธ์ค - ๋ฉ๋ด ๋ฆฌ๋ด์ผ (0) | 2022.07.27 |
[python]ํ๋ก๊ทธ๋๋จธ์ค - ๋น๋ฐ์ง๋ (0) | 2022.07.25 |
[python]ํ๋ก๊ทธ๋๋จธ์ค - ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์ (0) | 2022.07.12 |
๋๊ธ