-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek06_4.py
More file actions
42 lines (40 loc) · 820 Bytes
/
week06_4.py
File metadata and controls
42 lines (40 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from collections import deque
d = deque()
n = int(input())
for _ in range(n):
put = input()
if " " in put:
a, b = map(int, put.split())
else:
a = int(put)
if a == 1:
d.appendleft(b)
elif a == 2:
d.append(b)
elif a == 3:
if len(d) == 0:
print(-1)
else:
print(d.popleft())
elif a == 4:
if len(d) == 0:
print(-1)
else:
print(d.pop())
elif a == 5:
print(len(d))
elif a == 6:
if len(d) == 0:
print(1)
else:
print(0)
elif a == 7:
if len(d) == 0:
print(-1)
else:
print(d[0])
elif a == 8:
if len(d) == 0:
print(-1)
else:
print(d[len(d) - 1])