목록Python (20)
일상 코딩
MacOS 터미널 세팅 아래 링크 참조 후 설치 진행한다. https://polarcompass.tistory.com/140?category=514165 설치 $ brew install miniforge 삭제 $ brew uninstall miniforge conda 명령어 및 단축키 https://polarcompass.tistory.com/136?category=520069 Miniconda3 Conda 가상환경 설치 및 설정 Mini Conda 설치 1. 파이썬 버전별 설치 파일 다운로드 링크 ● Linux https://docs.conda.io/en/latest/miniconda.html#linux-installers Miniconda — Conda documentation Miniconda is..
Mini Conda 설치 파이썬 버전별 설치 파일 다운로드 링크 ● Linux https://docs.conda.io/en/latest/miniconda.html#linux-installers Miniconda — Conda documentation Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others. Use the conda in d..
https://comdoc.tistory.com/entry/Python-Zip-2%EC%B0%A8%EC%9B%90-%EB%B0%B0%EC%97%B4-%ED%9A%8C%EC%A0%84 Python Zip 2차원 배열 회전 1. zip 내장 함수(BIF) zip은 각 iterables의 요소들을 하나씩 모아 이터레이터를 만듭니다. iterable (이터러블) 멤버들을 한 번에 하나씩 돌려줄 수 있는 객체. 이터러블의 예로는 모든 (list, str, tuple 같 comdoc.tistory.com https://choichumji.tistory.com/74 [python] 2차원 리스트 90도 돌리기 def rotated(array_2d): list_of_tuples = zip(*array_2d[::-1])..
https://zidarn87.tistory.com/25 파이썬 리스트, 튜플 정렬하기 - sort(), sorted(), reverse() 파이썬 정렬하기 - sort(), sorted(), reverse() sort() 기본값은 오름차순 정렬이고, reverse옵션 True는 내림차순으로 정렬하게 됩니다. a= [3, 1, 9, 7, 5] a.sort() print(a) [1, 3, 5, 7, 9] a= [3, 1,.. zidarn87.tistory.com
https://chancoding.tistory.com/146 [파이썬] 함수에 입력 변수 여러개 받기 - 매개변수 파이썬에서 함수를 사용할 때 입력 값을 받아서 사용하는 경우가 많습니다. 함수에서 입력 값을 받을 때, 상황에 따라서 입력받는 값의 개수가 달라질 수 있는 경우가 생길 수 있습니다. 예를 들 chancoding.tistory.com
https://pythondocs.net/selenium/%EC%85%80%EB%A0%88%EB%8B%88%EC%9B%80-%ED%81%AC%EB%A1%A4%EB%9F%AC-%EA%B8%B0%EB%B3%B8-%EC%82%AC%EC%9A%A9%EB%B2%95/#%ED%85%8D%EC%8A%A4%ED%8A%B8_%EC%9E%85%EB%A0%A5 셀레니움 크롤러 기본 사용법 - 뻥뚫리는 파이썬 코드 모음 셀레니움 전반에 관하여 간략하게 정리한다. 사용 방법이나 예시는 따로 링크를 남기고 꾸준히 업데이트 하도록 하겠다. 아래 기능들만 익히면 웹상의 원하는 거의 대부분의 업무의 자동화가 pythondocs.net
class CompressedGene: def __init__(self, gene: str) -> None: self._compress(gene) # "_"은 클래스 외부에서 사용되지 않게 하기 위한 비공개 처리 문구이다. def _compress(self, gene: str) -> None: self.bit_string: int = 1 # 1로 시작/ 유전코드를 2진수로 변환 후 저장할 변수. for nucleotide in gene.upper(): self.bit_string > i & 0b11 # 마지막 2비트를 추출한다. if bits == 0b00: # A gene += "A" elif bits == 0b01: # C gene += "C" elif bits == 0b10: # G gene += ..
암호화 전체 코드는 아래와 같다. from secrets import token_bytes from typing import Tuple def random_key( length: int ) -> int: # length 만큼 임의의 바이트를 생성한다. tb: bytes = token_bytes(length) # token_byte() 메서드 사용하여 pseudo-random 데이터 생성한다. # 바이트를 비트 문자열로 변환한 후 반환한다. return int.from_bytes(tb,"big") # 암호화 과정 메소드 def encrypt( original: str ) -> Tuple[int, int]: original_bytes: bytes = original.encode() # 문자열을 encode(..
위의 식은 파이 계산을 위한 무한급수 라이프 니츠 공식(Leibniz Formula)이다. 이를 무한히 더하면 파이값을 가질 수 있게 된다. 이를 코드로 나타내면 import numpy as np import time def calculate_pi(n_terms:int) -> float: upNum: float = 4.0 downNum: float = 1.0 multiNum: float = 1.0 pi: float = 0.0 start = time.time() for _ in range(n_terms): pi += multiNum * ( upNum / downNum ) downNum += 2.0 multiNum *= -1.0 end = time.time() return pi, end-start if __..
part.00 메모이제이션을 이용한 피보나치 알고리즘 n = int(input()) memo = {0: 0, 1: 1} def fibo(n): if n in memo: return memo[n] else: ret = fibo(n-1) + fibo(n-2) memo[n] = ret return ret print(fibo(n)) 일반적인 리스트를 이용하는 것이 아닌, dictionary()를 이용하여 key값으로 value를 빠르게 찾도록 만들었다. part.01 아래 코드는 해보나치 수열 단일값을 출력하는 코드이다. from functools import lru_cache @lru_cache( maxsize = None ) def fib4( n: int ) -> int: if n < 2: # 기저조건 re..