https://www.youtube.com/watch?v=ZMfuDnUfdAc
강의를 보면서 문제를 푸는 방법을 배울 수 있었다.
-열거하다는 뜻의 함수로, 여러가지 자료형(list, set, tuple)을 인덱스를 포함한 객체로 리턴한다.
기본적으로 인덱스와 원소로 이루어진 튜플(tuple)을 만들어 준다.
from collections import deque
def solution(priorities,location):
printer =deque((i, p) for i, p in enumerate(priorities))
turn = 0
while printer:
job = printer.popleft() # 큐의 pop은 앞에서부터 꺼내옴
if any(job[1] < other_job[1] for other_job in printer):
printer.append(job)
else:
turn += 1 # 3. 내가 제일 중요하다면 수행하고 location과 비교한다.
if job[0] == location:
break;
return turn
print(solution([2,1,3,2],2))