전체 글 262

BeautifulSoup

HTML, XML 문서를 파싱하여 원하는 데이터를 쉽게 추출하는 Python 라이브러리 # 가상환경 활성화conda activate 이름# 환경 없으면 생성conda create -n 이름 python=3.11# 설치conda install -c conda-forge beautifulsoup4# 예제from bs4 import BeautifulSoup html_doc = """ 안녕하세요! 이건 예제 링크입니다. """ soup = BeautifulSoup(html_doc, 'html.parser') print("Title:",soup.title.string) print("Heading:", soup.h1.text) print("Link:",soup.a['href']) # api 크롤..

sql 문제 풀이

use madang;INSERT INTO book (bookid, bookname, publisher, price) VALUES(1, '축구의 역사', '굿스포츠', 7000),(2, '축구아는 여자', '나무수', 13000),(3, '축구의 이해', '대한미디어', 22000),(4, '골프 바이블', '대한미디어', 35000),(5, '피겨 교본', '굿스포츠', 8000),(6, '역도 단계별기술', '굿스포츠', 6000),(7, '야구의 추억', '이상미디어', 20000),(8, '야구를 부탁해', '이상미디어', 13000),(9, '올림픽 이야기', '삼성당', 7500),(10, 'Olympic Champions', 'Pearson', 13000);INSERT INTO customer..

collections.Counter

기본 사용법from collections import Countercnt = Counter(['a', 'b', 'a', 'c', 'b', 'a'])print(cnt)# Counter({'a': 3, 'b': 2, 'c': 1})내부적으로 딕셔너리처럼 작동 (key=요소, value=빈도)cnt['a'] → 3존재하지 않는 키는 자동으로 0 반환 (KeyError 안 남) 문자열Counter("banana")# Counter({'a': 3, 'n': 2, 'b': 1}) most_common() 많이 등장한 순으로 정렬된 리스트 반환cnt = Counter("banana")print(cnt.most_common()) # [('a', 3), ('n', 2), ('b', 1)]print(cnt.mo..

heap

기본 사용법 (최소 힙) 파이썬은 최소 힙만 가능import heapqheap = []# 원소 추가 (push)heapq.heappush(heap, 4)heapq.heappush(heap, 1)heapq.heappush(heap, 7)heapq.heappush(heap, 3)print(heap) # [1, 3, 7, 4] ← 내부적으로 힙 구조로 정렬되어 있음# 최솟값 꺼내기 (pop)smallest = heapq.heappop(heap)print(smallest) # 1print(heap) # [3, 4, 7] 리스트를 힙으로 한 번에 변환arr = [5, 3, 8, 1]heapq.heapify(arr)print(arr) # [1, 3, 8, 5] 최대힙파이썬 heapq는 기본이 최소 힙..