코딩테스트 (2) 썸네일형 리스트형 [문자를 순서대로 숫자로? a->1 , b->2] a는 1로 b는 2로 .... 이 순서대로 바꾸고 싶다면 if 문을 써서 문자 a를 만나면 1이다, b를 만나면 2다 .... 처럼 할 수도 있지만 ord('알파벳') 함수를 쓰면 쉽게 바꿀 수 있다. print(ord('a')) print(ord('A')) 위 코드의 결과로 다음과 같이 나온다. 97 65 따라서 소문자 a를 1로 바꾸는 기준으로 원하는 알파벳을 숫자로 바꾸고 싶다면 다음과 같이 실행시키면된다 # print(ord('원하는 알파벳')-ord('a')+1) print(ord('c')-ord('a')+1) 실행결과 : 3 알파벳,숫자,한글 모두 위와 같이 바꿀 수 있다. print('0:',ord('0')) print('1:',ord('1')) print('9:',ord('9')) prin.. [자료구조]우선순위 큐(Priority Queue)와 힙(Heap) 백준 1715번 문제를 풀다가 "우선 순위 큐(Priority Queue)"에 대해 알게 되었고 우선순위 큐를 구현하기 위해 파이썬의 heapq 모듈 사용 중 heapq.heappush 하는 과정이 이해가 가지 않아서 이를 계기로 '나동빈'님의 영상을 보게 되었습니다. import heapq #heap 라이브러리 importheap_list = []iterable =[3,5,9,6,4] for value in iterable : heapq.heappush(heap_list,value) #heap 라이브러리의 heappush 함수를 이용해서 iterable의 원소를 heap_list에 추가 print(heap_list) 위의 코드는 파이썬에서 heap 라이브러리를 import하고 heapq.heappu.. 이전 1 다음