내가 파이썬으로 코테 풀면서 기억해두면 좋을 것들을 짧게 정리해놓은 글.
단독 게시글로 쓰기는 애매해 모아서 작성했다.
input() -> sys.std.realine() 으로 바꾼다.
def rotate_90(m):
N = len(m)
ret = [[0] * N for _ in range(N)] # 행렬 생성하기
for r in range(N):
for c in range(N):
ret[c][N-1-r] = m[r][c] # 이게포인트이다.
return ret
heapq.heappush(힙이름,item) # 아이템을 힙에 추가
heapq.heappop(힙이름) # 힙에서 가장 작은 원소를 POP & return
heapq.heapify(x) # 리스트 x를 즉각적으로 heap으로 바꾼다.
from collections import Counter
print(Counter('hello world'))
# 메소드 : most_common
# 데이터의 개수가 가장 많은 순으로 정렬된 배열을 리턴 한다.
print(Counter('you put me up, and you put me down').most_common())
# 숫자만큼 리턴함
print(Counter('you put me up, and you put me down').most_common(2))
a = Counter(['shake it on','hot property'])
b = Counter(['space cowboy','little l','canned heat','shake it on'])
print(a)
print(b)
print(a+b)
# 뺄때는 이렇게 한다.
a.subtract(b)
print(a)
a&b
a|b
tuple1 = (1,2,'a','b')
print(tuple1[0])
print(len(tuple1))
x, _, y = (1, 2, 3,)
print(x, y)
x, *_, y = (1,2,3,4,5,6,7,8)
print(x,y)
for _ in range(3):
print("악")
# 따로 i를 사용하지 않아도 반복문 이가능하다.
positive = float('inf')
print(positive)
negative = float('-inf')
print(negative)
from collections import deque
queue = deque()
queue.append(5)
queue.append(1)
queue.append(4)
queue.append(3)
queue.popleft()
print(queue)
queue.append(9)
queue.popleft()
print(queue)
#나중에 들어온 요소부터 출력
queue.reverse()
print(queue)
from queue import PriorityQueue
que = PriorityQueue()
que = PriorityQueue(maxsize=8)
#이럴 경우 8로 설정됨
que.put(4)
que.put(7)
que.put(1)
que.put(3)
que.put(8,'IU')
que.get()
print(que.get())