File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ #2024.12.14, 30min
2+ def solution (record ):
3+ answer = []
4+ # 1. history와 user_db DB 정의
5+ user_db = {} # key=uid , value = username
6+ history = [] # ["Enter / Leave" , uid ]
7+
8+ #2. history와 user_db 기록 시작
9+ for r in record :
10+ command = r .split () # command = [동사V ,userid ,(username)]
11+ v = command [0 ]
12+ uid = command [1 ]
13+ # 2-1 Enter : user_db 추가 , history 추가
14+ if v == 'Enter' :
15+ user_db [uid ] = command [2 ] # user_db[uid] = username
16+ history .append ([uid ,v ]) # history: [uid , "Enter" ]
17+ #2-2 Leave :history 추가
18+ elif v == 'Leave' :
19+ history .append ([uid ,v ]) # history: [uid , "Leave" ]
20+ #2-3 Change : user_db 수정(username 변경)
21+ elif v == 'Change' :
22+ user_db [uid ] = command [2 ] #user_db[uid] = new_username
23+
24+ # 3.user_db, histoy 기반으로 문자열 배열 result를 만들기
25+ result = list ()
26+ # 영어 v 을 한국어 동사로 번역
27+ en_to_ko = {'Enter' :'들어왔습니다.' ,'Leave' : '나갔습니다.' }
28+ for uid , h_v in history :
29+ user_name = user_db [uid ]
30+ result .append (f"{ user_name } 님이 { en_to_ko [h_v ]} " )
31+
32+ return result
You can’t perform that action at this time.
0 commit comments