전체보기

    Tool Box 3

    콜라츠 추측(짝수면 / 2 홀수면 3n + 1로 최종값은 결국 1이 됨) """ 입출력 예 nresult 10[10, 5, 16, 8, 4, 2, 1] """ def solution(n): answer = [n] while n != 1: if n % 2 == 0: n = n // 2 else: n = 3 * n + 1 answer.append(n) return answer 주사위 문제 (총 4개의 주사위를 굴려서 값이 4개 혹은 3개 혹은 2개씩 같은 경우) def solution(a, b, c, d): # 주어진 주사위 숫자들을 정렬하여 작은 숫자부터 처리하기 위해 준비합니다. dice = sorted([a, b, c, d]) # 모든 주사위의 숫자가 동일한 경우 if dice[0] == dice[3]..

    Tool Box 2

    인접한 원소들의 차이를 확인 한 수 조작 def solution(numLog): answer = [] for i in range(1, len(numLog)): minus = numLog[i] - numLog[i - 1] if minus == 1: answer.append("w") elif minus == -1: answer.append("s") elif minus == 10: answer.append("d") elif minus == -10: answer.append("a") return "".join(answer) 리스트의 값을 다른 리스트의 값으로 대체 arr[0, 1, 2, 3, 4] queries[[0, 3],[1, 2],[1, 4]] 결과 [3, 4, 1, 0, 2] def solution(ar..

    Tool Box

    대문자 → 소문자, 소문자 → 대문자 str = input() str = str.swapcase() str = input() a = "" for i in str: if i.isupper(): a = a + i.lower() else: a = a + i.upper() print(a) 일부 특수문자 출력 작은따옴표('), 큰따옴표(") 같은 경우 백슬래시(\)를 활용 ex) \'\" print("!@#$%^&*(\\'\"?:;)") 양쪽 공백 제거, 개행문자(\n) 제거 s = " Hello World " s = s.strip() # 양쪽 공백 제거 print(s) 홀짝구분 a = int(input()) if a % 2 == 0: print(f"{a} is even") else: print(f"{a} is ..

    most likely due to a circular import 오류, 순환 참조(circular reference)

    most likely due to a circular import 오류, 순환 참조(circular reference)

    ● 발생한 이유 category는 posts의 FK이다. 역참조를 이용하여 Category에 속한 post 객체들을 가져오려는 상황에서 posts의 serializers.py에 PostListSerializer class가 정의되어 있고 category 필드가 CategorySerializer를 참조하고 있는 상태이다. 즉 서로를 참조하게 되어 순환 참조 오류가 발생하게 되었다. categories폴더의 serializers.py의 CategorySerializer class의 post 필드에서 PostListSerializer를 참조하고 있다 이렇듯 서로를 참조하게 되면 계속해서 무한히 재귀적으로 호출하게 되어 메모리 누수나, 변수 값 설정이 잘못되는 문제가 발생하게 된다. ● 해결 운영체제를 공부 할..