일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- preprocessing
- Unity
- dbms
- spring
- systemd
- Operator
- 백준
- 리눅스 마스터 1급
- Java
- OOP
- X윈도우
- python
- Binary Search
- 리눅스
- External Scheme
- Entity Set
- Physical Scheme
- descriptive statistics
- Entity
- 셀레니움
- literal
- Reference Type
- selenium
- Mac
- 자바
- BFS
- Polymolphism
- Inheritance
- Class
- X.org
- Today
- Total
목록Programming Language/Python (12)
Byeol Lo
정렬에는 두 가지의 유형으로 나눌 수 있는데 하나는 Stable이고, 다른 하나는 In-place가 있다. Stable Sorting 어떤 배열을 정렬했을때, 같은 값들은 그 값들 내에서 배열의 순서에 맞게 정렬되는 것, 즉 어떤 a는 2번째에 있고 b는 5번째에 있다고 치자. a와 b에 들어있는 값이 같으면, a, b로 정렬되는 것을 말한다. b, a로 정렬되면 Unstable Sorting이라고 한다. Sep Example Stable Sorting Insertion Sort Merge Sort Bubble Sort Counting Sort Unstable Sorting Selection Sort Heap Sort Shell Sort Quick Sort In-place Algorithm 원소들의 개수..
from collections import deque graph = [ [1,1,1,0,0], [1,0,1,0,1], [1,1,1,1,1], [1,1,0,0,1], [1,1,1,1,1] ] dx = [1,-1,0,0] dy = [0,0,1,-1] visited = [[False]*5 for _ in range(5)] path = deque() def solution(graph, visited, x, y) : visited[y][x] = True path = deque([[x, y]]) while path : x, y = path.popleft() for i in range(4) : pos1, pos2 = x+dx[i], y+dy[i] if 0
미로 문제가 나왔을때 다음과 같이 변수들을 선언하고 알고리즘을 짠다. graph = [ [1,1,1,0,1], [1,0,1,1,1], [1,1,1,0,1], [1,0,1,0,1], [1,1,1,1,1] ] visited = [[False]*len(graph[0]) for _ in range(len(graph))] dx = [1,-1,0,0] dy = [0,0,1,-1] def solution(graph, visited, x, y, walk) : if not visited[y][x] or visited[y][x] > walk : visited[y][x] = walk else : return for i in range(4) : pos1 = x+dx[i] pos2 = y+dy[i] # indexerror가 난..
직사각형이 다음과 같이 주어진다고 하자. (x1, y1, x2, y2) 좌표계는 1부터 50까지 있다고 치면, 많은 직사각형들에 대해 외곽을 다음 로직을 통해 list로 구현 할 수 있다. def draw(rectangles) : map = [[9]*50 for _ in range(50)] for rect in rectangles : for x in range(rect[0], rect[2]+1) : for y in range(rect[1], rect[3]+1) : if rect[0] < x < rect[2] and rect[1] < y < rect[3] : map[y][x] = 0 elif map[y][x] : map[y][x] = 1 for i in map : print(*i) if __name__ =..
reduce 함수는 리스트 들에 대해 어떠한 연산을 누적하여 수행하고 싶을때 쓸 수 있는 함수이다. 예를 들어 [1,3,5,67,4,5]라는 리스트를 다 더하고 싶다면 다음과 같이 적으면 된다. from functools import reduce lst = [1,3,5,67,4,5] print(reduce(lambda x, y: x+y, lst)) # 85 lambda 식이 아니더라도 사용자 정의 함수로 다가갈 수 있다. 파이썬 3.9에서는 @functools.cache라는 함수가 있는데 데코레이터로 쓴다면 값들을 저장하여 다시 그 연산을 수행할때, 연산을 안하고 바로 호출 할 수 있도록 한다. 이를 메모이제이션이라고 말하는데, 동일한 계산의 반복 수행을 제거하여 최적화하는 기술이다. 계산이 무거울 때 ..
from operator import itemgetter, attrgetter student_tuples = [ ('수학', 105), ('영어', 140), ('과학', 133), ('국어', 100) ] class Student : def __init__(self, name, grade, age) : self.name = name self.grade = grade self.age = age def __repr__(self) : return repr((self.name, self.grade, self.age)) student_objects = [ Student('홍길동', "A+", 22), Student('아이유', "A0", 20), Student('김구', "A+", 21), Student('야스..
Numpy 는 행렬 연산에 특화된 자료구조와 연산을 지원하는 라이브러리이다. pip install pip --upgrade pip install numpy # pip install numpy --upgrade # pip uninstall numpy 위의 pipeline 명령어들을 통해 numpy를 설치, 삭제, 업데이트가 가능하다. import numpy as np arr1 = np.array([[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9]]) arr2 = np.array([1,2,3,4,5]) arr3 = 1 print(arr1 + arr2) print("==============") print(arr2 + arr3) print("======..
다음 함수를 가져와서 쓰면 된다. from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selelnium import webdriver url = 'https://www.naver.com/' options = webdriver.ChromeOptions() options.add_argument("headless") driver = webdriver.Chrome(options=options) driver.get(url) WebDriverWait(driver, 2..
다음 options을 세팅하자! from selenium import webdriver from selenium.webdriver.chrome.options import Options import chromedriver_autoinstaller chromedriver_autoinstaller.install("./") chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--log-level=3') # 브라우저 로그 레벨을 낮춤 chrome_options.add_argument('--disable-loging') # 로그를 남기지 않음 driver = webdriver.Chrome(ch..
다음 외장 모듈을 설치해서 사용하면 편리하다. pip install chromedriver_autoinstaller 설치 완료가 되었으면 다음 코드를 실행한다. from selenium import webdriver import chromedriver_autoinstaller chromedriver_autoinstaller.install("경로") driver = webdriver.Chrome("경로") url = "https://google.com" driver.get(url)