PS73 프로그래머스 오픈채팅방 python 1. 문제 2. 풀이 dictionary 형태 사용하기 3. 구현 def solution(record): answer = [] dic={} for item in record: item = item.split(' ') # item.split(' ') 하면 달라지는 것이 없다. if item[0] != 'Leave': dic[item[1]] = item[2] for item in record: item = item.split(' ') if item[0]=='Enter': answer.append(f"{dic[item[1]]}님이 들어왔습니다.") if item[0]=='Leave': answer.append(f"{dic[item[1]]}님이 나갔습니다.") return answer 2021. 6. 14. 프로그래머스 124나라의 숫자 python 1.문제 2.풀이 q,r = divmod(N, Q) 단점은 조금 느리다는 것. 3.구현 def solution(n): answer = '' if n 2021. 6. 14. 프로그래머스 튜플 python 1. 문제 2. 풀이 1) string을 list 형태로 만든다 2) 원소를 크기 순서대로 정렬해서 앞의 집합에 없는 원소를 추가한다. 3. 구현 1) .split을 잘 써서 string을 분리하면 훨씬 깔끔해짐. 2) 원소의 크기로 정렬할 때는 .sort(key=len) 3) 원소가 있는 지 아닌 지 확인할 때 for item (not) in list: 하면 된다. 내풀이 def solution(s): answer = [] tmp=[] tmpList =[] tmpNum=0 for ch in s: if ch.isdigit(): tmpNum=int(ch)+tmpNum*10 if ch==',': if tmpNum == 0: continue else: tmp.append(tmpNum) tmpNum=0 if c.. 2021. 6. 13. 프로그래머스 문자열압축 python 1. 문제 2. 풀이 단순구현 3. 구현 > TypeError: string indices must be integers 문제는tmpStr = s[0, int(step)] 이었다. string indice를 하려면 다음과 같이 적어야한다. tmpStr = s[0:step] def solution(s): answer = 0 le = len(s) for step in range(1, le+1): cnt=0 tmpStr = s[0, int(step)] for i in range(0, le+1, step): if tmpstr == s[i, i+int(step)]: cnt+=1 else: if cnt==1: answer+=tmpStr else: answer+=cnt answer+=tmpStr cnt=0 retur.. 2021. 6. 12. 이전 1 ··· 13 14 15 16 17 18 19 다음 반응형