프로그래밍 공부/Python(3)
-
실전으로 배우는 전략 패턴 (Strategy Pattern) – 트레이딩 봇에서 OOP 활용하기 w.Python
전략 패턴이란?전략 패턴(Strategy Pattern)은 알고리즘(전략)의 동적 교체를 가능하게 해주는 객체지향 디자인 패턴입니다.행동(Behavior)을 캡슐화하고, 런타임 시에 객체에 전략을 주입해 변경 가능한 유연한 구조를 만들 수 있도록 도와줍니다.“변화하는 부분을 분리하고, 고정된 부분은 그대로 두자”는 OOP 원칙의 대표 사례입니다.https://github.com/99mini/trading 에서 소스코드를 확인할 수 있습니다.구조 요약trading-bot/├── .venv/ # 가상환경├── .gitignore├── requirements.in # 의존성 명시├── requirements.txt # 고..
2025.04.25 -
[Python] Collections 모듈: counter, most_common
counter 함수 collections.Counter(iterable): return dict 예제코드 import collections a = [1,2,3,4,1,1,2,3,4] b = [1,2,3,4,1,1,5,6,7] print(collections.Counter(a),'\n', collections.Counter(b)) print(type(collections.Counter(a))) 결과 >>> Counter({1: 3, 2: 2, 3: 2, 4: 2}) Counter({1: 3, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1}) counter 연산 +, -, &(교집합), |(교집합) 연산 가능 예제코드 import collections a = [1,2,3,4,1..
2022.03.19 -
[Python] 순열, 조합, 중복순열, 중복조합
1. 순열 permutations(Iterable, r) # 순열 from itertools import permutations for i in permutations([1,2,3,4], 2): print(i, end=" ") # (1, 2) (1, 3) (1, 4) (2, 1) (2, 3) (2, 4) (3, 1) (3, 2) (3, 4) (4, 1) (4, 2) (4, 3) 2. 조합 combinations(Iterable, r) # 조합 from itertools import combinations for i in combinations([1,2,3,4], 2): print(i, end=" ") # (1, 2) (1, 3) (1, 4) (2, 3) (2, 4) (3, 4) 3. 중복순열 produc..
2021.09.30