from collections import deque
def solution(priorities, location):
que = deque()
for p, l in enumerate(priorities): # (인덱스, 우선순위)라서
que.append((p, l)) # (l, p)여야 함
cnt = 0
while True:
MAX = max(que, key = lambda x: x[1])
if que[0] == MAX:
if que[0][0] == location:
cnt += 1
break
que.popleft()
cnt += 1
else:
que.rotate(-1)
return cnt
def solution(priorities, location):
que = [(l, p) for l, p in enumerate(priorities)]
cnt = 0
while True:
item = que.pop(0)
if any(item[1] < q[1] for q in que):
que.append(item)
else:
cnt += 1
if item[0] == location:
return cnt
any(item[1] < q[1] for q in que):
que.append(item)
자료 요소들이 다 False면 False, 하나라도 True면 True
l = [False, False, True]
print(any(l)) # True
l = [False, False]
print(any(l)) # False
l = [4, 5, 6]
print(any(l)) # True
t = (0, 0, False)
print(any(t)) # False
s = {1, 0, 3, False}
print(any(s)) # True
# Empty
l, t, s = [], (), {}
print(any(l), any(t), any(s)) # False False False
d = {1: "Hello", 0: "Hi"}
print(any(d)) # True
d = {False: "Hello", 0: "Hi"}
print(any(d)) # False
d = {}
print(any(d)) # False
s = "Hi"
print(any(s)) # True
s = "0"
print(any(s)) # True
s = ""
print(any(s)) # False
l = [3, 5, 7, 8, 12]
condition = any(i > 10 for i in l)
print(condition) # True
def my_any(l):
for item in l:
if item:
return True
return False
x = [3, 2, 1]
print(my_any(x)) # True
y = []
print(my_any(y)) # False
from collections import deque
def solution(priorities, location):
que = deque((p, l) for l, p in enumerate(priorities))
print(que)
cnt = 0
while True:
item = que.popleft()
if que and max(que)[0] > item[0]:
que.append(item)
else:
cnt += 1
if item[1] == location:
break
return cnt