본문 바로가기

Data Science/Programming10

python programing 수업 노트: strings StringSlice: backward & last stringsword = testword[::-1]word[-2:]Methodsstring.lower() & string.upper()UPPER = text.upper()lower = text.lower()# re-allocationstring.capitalize()Capitalize = text.capitalize()# re-allocationsplit & join# string to listtext_list = string.split()# list to stringnew_string = ' '.join(text_list)replacestring.replace(old, new, count)Package: Counter()from collections .. 2026. 9. 9.
python programing 수업 노트: functions 1. Review for Loop“When they stop?”break: stops loop immediatelycontinue: skips to the next iteration# break# continue2. FunctionsPackages: math, timeimport math #, time (X), import separatelyimport timeTime: end_time - start_timeimport mathtime_start = time()for i in range(0, 2000000): math.sqrt(i)time_end = time()print('This took', time_end - time_start, 'seconds.')# Output# This took 0.18.. 2026. 9. 9.
python Variablesprint Comparingpriority 'If' While loops For loops 2026. 9. 8.
python 리스트 원소 제거: remove, pop, del, list comprehension, clear 프로그래머스 코딩테스트 '없는 숫자 더하기' 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr아이디어full_numbers = [0부터 9까지]에서numbers 입력값에 있는 수 제거full_numbers에 남은 숫자 합1. 값으로 제거: remove()fruits = ["apple", "banana", "orange", "banana"]fruits.remove("banana")print(fruits) # ['apple', 'orange', 'banana']* 값이 없으면 ValueError 발생2. 인덱스로 제거: pop()fruits = ["apple", "banana", "orange"]item = fr.. 2026. 6. 2.
python 엘리스 코딩 챌린지 Elice Coding Challenge Day7: 동적계획법, 계기판 조작하기 문제 Lesson동적 계획법: DP, Dynamic Programming: 이전 값을 재사용: 분할정복(Divide & Conquer)와 비슷하지만 중간 결과 저장하여 효율성 증대Tabulation (bottom-up)for i in range(2, N) dp[i] = dp[i-1] + dp[i-2]Memorization (top-down)def fibo(N): if N >> 이거 어제 문제풀 때, 쓰고 싶었던 거다.동적계획법 사용 조건겹치는 부분 (overlapping subproblem)최적 부분 구조 (optimal substructure)재귀함수 반복 시 시간↑  >> 저장! Question1≤ N≤ 10^71≤ K≤ 10input100000 3N = 100000K = 3>>> N보다 크면서 K개의 숫.. 2024. 7. 17.
python 엘리스 코딩 챌린지 Elice Coding Challenge Day6: 너비 우선 탐색 BFS Lesson너비 우선 탐색: BFS (Breadth First Search): 하나의 노드에서 차례대로 모든 노드 방문 (인접 노드부터)>> 최단 경로 혹은 임의의 경로 찾을 때 사용주로 Queue 사용무한 루프 주의시간복잡도 : 인접리스트 O(V+E), 인접행렬 O(V^2)from collections import deque1 = deque()q.append(st)visited(st) = 1while q: now = q.popleft() print(now, end=" ") for next in v[now]: if now visited(next): visited[next] = 1 q.append(next) DFS vs. BFS공통점시작부터 목적지 노드까.. 2024. 7. 16.
728x90