프로그래머스(파이썬)

    기능 개발→ deque, 이중 while문★, 미친 for문★, 갱신★

    나의 풀이 from collections import deque import math def solution(progresses, speeds): tmp=[] for x in progresses: tmp.append(100-x) required_days=[math.ceil(x/y) for x,y in zip(tmp, speeds)] que=deque(required_days) print(que) #deque([7, 3, 9, 4, 1, 5]) result = [] #que에 있는 값을 소거하는 방법으로 접근 while que: count = 0 #최초 first는 7이다. #두번째 first는 9이다. first = que[0] #첫번째 7

    튜플→Counter, 정규식, most_common(), split()★★

    나의 풀이 import re from collections import Counter def solution(s): result = [] answer =re.sub(r'[^\d,]', '', s) list_tmp = answer.split(',') tmp=(Counter(list_tmp)) most_common = tmp.most_common() for x,y in most_common: result.append(int(x)) return result ▶ 문자열 s가 입력되었을 때 숫자와 콤마(,)를 제외한 모든 문자를 소거한다. ▶ 콤마를 구분자로(,)로 문자열을 쪼갠다. ▶ Counter함수를 써서 각 요소별 빈도수를 구한다. ▶ most_common()함수를 써서 빈도수가 높은 순서대로 정렬한다.

    위장★★→ Counter(), reduce() 모든 요소의 곱 + 모든 요소에 +1

    나의 풀이 from collections import Counter from functools import reduce def solution(clothes): tmp=[] for x, y in clothes: tmp.append(y) #요소별 개수를 파악함 tmp_set=Counter(tmp) #요소에 대한 value값만 저장함 tmp_value=tmp_set.values() #tmp_value의 모든 요소에 1을 더함 tmp_value_plus = list(map(lambda value: value+1, tmp_value)) #tmp_value_plus에 있는 모든 요소를 곱한다. tmp_total=reduce(lambda x,y : x*y, tmp_value_plus) #아무 것도 안 입는 경우를 ..

    괄호 회전하기★★→ rotate() 사용O + rotate() 사용X 문자열 밀기

    나의 풀이 from collections import * def solution(s): cnt=0 stack=[] que=deque(s) for i in range(len(s)): #왼쪽으로 1칸씩 이동시킨다. que.rotate(-1) tmp=list(que) #bracket_judge함수의 리턴값이 True이면 올바른 괄호 문자열이라고 판단 if bracket_judge(tmp) == True: cnt+=1 return cnt def bracket_judge(tmp): answer =True stack=[] dict = { '(':')', '[':']', '{':'}'} for i in range(len(tmp)): if tmp[i] in ['(', '[', '{']: #이 코드 부분에서 tmp[i]..