본문 바로가기

전체 글824

Sum of odd numbers Description: Given the triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output) 1 --> 1 2 --> 3 + 5 = 8 Solution: 1. Add up all 'n' numbers. 2. Find the odd number by the added number. 3. It returns after adding 'n' odd numbers from the last. def row_sum_odd_num.. 2022. 4. 28.
Python _ 런타임 중에 스크립트 파일 실행하기 스크립트는 보통 직접 명령어를 입력해 실행합니다. 하지만 runtime 환경에서 스크립트 파일을 실행해야할 때도 있습니다. 그런 경우에는 개발자가 직접 터미널에 스크립트 실행 명령어를 치는 것이 아닌, 미리 작성된 파이썬 코드에 의해 스크립트가 실행되도록 해야합니다. 이번 글에는 OS를 사용한 스크립트 실행 방법을 알려드리겠습니다. OS import os os.system("ls") 방법은 아주 간단합니다. os를 import 하고 system 메서드를 사용해 명령어를 안에 넣습니다. 그리고 실행을 해보면 그 결과 값도 함께 보여줍니다. (ls 는 해당 디렉토리를 보여줍니다) >>> project 현재는 project 폴더만 보이네요 하지만 스크립트를 실행하기 위해서 폴더 내로 이동해야 한다고 가정해봅시.. 2022. 4. 28.
Mumbling Description: This time no story, no theory. The examples below show you how to write function accum: Examples: accum("abcd") -> "A-Bb-Ccc-Dddd" accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" accum("cwAt") -> "C-Ww-Aaa-Tttt" The parameter of accum is a string which includes only letters from a..z and A..Z. Solution: 1. Extract each character from a string with an index. 2. Characters ar.. 2022. 4. 27.
Pytest _ client 에서 parmas 값 넣는 방법 테스트 코드를 작성하다보면 client를 사용해 uri요청을 보낼 때가 있습니다. 그리고 쿼리 파라미터(query string)는 패스 파라미터와 마찬가지로 uri를 텍스트로 작성해 보낼 수 있습니다. uri를 만드는 방법 세 가지를 함께 보겠습니다. 방법1. 일반 텍스트 response = client.get( "http://0.0.0.0:8000/users?limit=10&offset=0" ) 하지만 텍스트로만 작성할 경우, 하나의 케이스만 테스트 할 수 있는 정적 값이 되고 맙니다. 방법2. f-string 다음처럼 f-string을 통해 동적 값을 넣어줄 수 있습니다. limit = 10 offset = 0 response = client.get( f"http://0.0.0.0:8000/users.. 2022. 4. 27.
Two to One Description: Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters - each taken only once - coming from s1 or s2. Examples: a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq" longest(a, b) -> "abcdefklmopqwxy" a = "abcdefghijklmnopqrstuvwxyz" longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" Solution: 1. Concatenate strin.. 2022. 4. 26.
컬럼 속성 변경 후 alembic migration할 때 ‘None’ 생기는 현상 테이블 컬럼의 속성을 변경하고 alembic migration 할 때 version 파일에 None이 생기는 현상을 발견했습니다. 의도 일단 저는 stock 테이블에서 code와 name컬럼의 속성을 unique로 변경하고자 했습니다. # models.py class Stock(Base): __tablename__ = "stock" id = Column(Integer, primary_key=True, autoincrement=True) code = Column(String(50), unique=True) # unique=True 속성 추가 name = Column(String(50), unique=True) # unique=True 속성 추가 market = Column(ENUM("KOSPI", "KOS.. 2022. 4. 26.