Programming/Python

[HSAT 6회 정기 코딩 인증평가 기출] 출퇴근길 문제를 풀다가 인자로 배열 100,000개를 100,000번 호출한 정답과전역변수를 사용해서 효율적으로 처리한 정답이 거의 동일한 시간초가 나왔다.100,000 X 100,000 =  4*100억 byte이다.그렇다면 10Gbyte를 사용한 것인데 시간초과도 안 뜨고 왜 가장 큰 문제인 memory exceed도 나지 않았을까?  https://softeer.ai/practice/6248 Softeer - 현대자동차그룹 SW인재확보플랫폼 softeer.ai 해당 코드는 다음과 같다.def dfs(now, adj, visit): # 목적지 if visit[now]==1: return else: visit[now] = ..
자료구조 시간에 heap은 Priority Queue라고 배웠습니다. 그럼 파이썬 라이브러리에서는 2개 다 존재하는데 이 차이점은 뭘까? 내부로직은 heapq를 사용하고 있었다. 그럼 차이점은 뭘까? https://stackoverflow.com/questions/36991716/whats-the-difference-between-heapq-and-priorityqueue-in-python What's the difference between heapq and PriorityQueue in python? In python there's a built-in heapq algorithm that gives you push, pop, nlargest, nsmallest... etc that you can ap..
자료구조 시간에 heap은 Priority Queue라고 배웠습니다. 그럼 파이썬 라이브러리에서 이 차이점은 뭘까? 차이점을 알기 위해서는 선행되어 알아야 하는 개념 2가지가 필요합니다. 1) GIL 2) thread-safe, Thread-Non-Safe # 선행되는 개념보고 다음글로 넘어가기 👉 👉 https://codewizard.tistory.com/53 [Python] Priority Queue, heapq의 차이점 자료구조 시간에 heap은 Priority Queue라고 배웠습니다. 그럼 파이썬 라이브러리에서는 2개 다 존재하는데 이 차이점은 뭘까? 내부로직은 heapq를 사용하고 있었다. 그럼 차이점은 뭘까? https://stackoverf codewizard.tistory.com # GI..
파이썬에서 클래스를 생성할 때, 모든 메소드의 첫 인자를 "self" 라는 키워드를 놓습니다. 이유는 무엇일까요? class Person: def __init__(self, name, job): self.name = name self.job = job def introduce(self): return f"내 이름은 {self.name}, {self.job}이죠" 라고 두었을 때 p = Person("코난", "탐정") print(p.introduce()) 내 이름은 코난, 탐정이죠 이런 결과가 나온다. 여기서 self는 "인스턴스 자기 자신을 의미" 합니다. 그림으로 나타내면 다음과 같다. 여기서 __init__ 의 매개변수 self에 들어가는 값은 Person이라 할 수 있습니다. self는 그러면 p..
combinations, permutations 문제를 풀다가 생긴 문제이다. 조합, 순열의 결과 값은 튜플형태로 나온다. 예를 들어, from itertools import combinations, permutations import sys num = sys.stdin.readline().rstrip() x = [num[i] for i in range(len(num))] permus = [] for i in range(1, len(x)+1): permu = list(permutations(x,i)) print(permu) 위코드는 "리스트에 해당하는 모든 순열"을 구하는 코드이다. input output 127 [('1',), ('2',), ('7',)] [('1', '2'), ('1', '7'), (..