Dia Egg - Shugo Chara
반응형

분류 전체보기 179

(Python) count 함수 활용법

count 함수 문자열 안에서 찾고 싶은 문자의 개수를 찾을 수 있는 함수로, 튜플, 리스트, 집합과 같은 반복 가능한 iterable 자료형에서도 사용 가능하다. (dictionary나 set에서는 사용 불가능하다.) 사용방법 : 변수. count(찾는 요소) 문자열 한문자도 가능하고 'students'.count('t') #출력# 2 문자열도 가능하다 (띄어쓰기의 경우 포함안됨) 'studentsts'.count('st') #출력# 2 리스트 한문자 a = [1, 1, 1, 2, 3] a.count(1) #출력# 3 문자열 ['st', 's', 't', 'ststst'].count('st') #출력# 1

Algorithm/TeamNote 2023.06.19

(Python) 카드 뭉치(프로그래머스 Lv.1)

카드 뭉치(프로그래머스 Lv.1)https://school.programmers.co.kr/learn/courses/30/lessons/159994 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 내 코드def solution(cards1, cards2, goal): answer = "Yes" locate_1, locate_2 = 0, 0 for go in goal: if locate_1 파이썬은 선빵필승의 코드, list 범위를 넘지 않도록 아래처럼 범위를 잡아주어야 했다. if locate_1

(Python) 모의고사 (프로그래머스 Lv1)

모의고사 (프로그래머스 Lv1) https://school.programmers.co.kr/learn/courses/30/lessons/42840 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(answers): tmp_answer = [0]*3 way_1 = [1,2,3,4,5] way_2 = [2,1,2,3,2,4,2,5] way_3 = [3,3,1,1,2,2,4,4,5,5] answer = [] for i in range(len(answers)): if answers[i] == way_1[i%(len(way_1))]: ..

(Python) 과일 장수 (프로그래머스 Lv.1)

과일 장수 (프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/135808 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(k, m, score): answer = 0 score.sort(reverse =True) start = 0 while(start + m

(Python) 명예의 전당(1) (프로그래머스 Lv.1)

명예의 전당(1) (프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/138477 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(k, score): answer = [] honor = [] today = 0 for i in range(len(score)): today += 1 if today > k: honor.append(score[i]) honor.sort(reverse = True) honor.pop() answer.append(honor[-..

(Python) 폰켓몬 (프로그래머스 Lv.1)

폰켓몬 (프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/1845 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(nums): answer = 0 get_mon = len(nums)//2 mon = {} for i in range(len(nums)): mon[nums[i]] =0 if len(mon)>= get_mon: return get_mon answer = len(mon) return answer 딕셔너리에서 같은 key는 지워진다는 원리를 ..

(Python) 2016년 (프로그래머스 Lv.1)

2016년 (프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/12901 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(a, b): answer = '' month = [31,29,31,30,31,30,31,31,30,31,30,31] week = ['SUN','MON','TUE','WED','THU','FRI','SAT'] day = 0 #b를 그대로 더해야 하니까 0부터 시작 for i in range(a-1):#예를 들어 3월은 2월까지의 일..

(Python) 가장 가까운 같은 글자 (프로그래머스 Lv.1)/key in dic

가장 가까운 같은 글자 (프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/142086 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(s): answer = [] count ={} for i in range(len(s)): if s[i] not in count: answer.append(-1) count[s[i]] = i else: answer.append(i-count[s[i]]) count[s[i]] = i return answer 딕셔너리를 ..

(Python) 콜라 (프로그래머스 Lv.1)

콜라 (프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/132267 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(a, b, n): answer = 0 rest = 0 while(n>=a): rest = n%a n = n//a*b answer += n n += rest return answer rest라는 남는 병을 저장해주는 변수를 따로 지정해서 모드를 짜봤다. rest가 나눌 거 다 나누고 마지막에 들어가야 한다.

(Python) 푸드 파이트 대회(프로그래머스 Lv.1) /[::-1]활용

푸드 파이트 대회(프로그래머스 Lv.1) https://school.programmers.co.kr/learn/courses/30/lessons/134240 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(food): answer = '' for i in range(1,len(food)): if food[i] > 1: answer += food[i]//2*str(i) answer += '0' answer += answer[len(answer)-2::-1] return answer 크게 어려웠던 부분은 없었고 기억 해야 할 부..

반응형