-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-lists.py
53 lines (47 loc) · 1.26 KB
/
python-lists.py
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
43
44
45
46
47
48
49
50
51
52
def execute_commands(commands):
ls = []
for command in commands:
parts = command.split()
if parts[0] == "print":
yield str(ls)
elif parts[0] == "insert":
ls.insert(int(parts[1]), int(parts[2]))
elif parts[0] == "remove":
ls.remove(int(parts[1]))
elif parts[0] == "append":
ls.append(int(parts[1]))
elif parts[0] == "sort":
ls.sort()
elif parts[0] == "pop":
ls.pop()
elif parts[0] == "reverse":
ls.reverse()
else:
# print (parts[0])
yield "unimplemented: ", parts
def test_command_reader():
assert list(execute_commands([])) == []
assert list(execute_commands(['print'])) == ['[]']
assert list(execute_commands([
'insert 0 5',
'insert 1 10',
'insert 0 6',
'print',
'remove 6',
'append 9',
'append 1',
'sort',
'print',
'pop',
'reverse',
'print',
])) == [
'[6, 5, 10]',
'[1, 5, 9, 10]',
'[9, 5, 1]',
]
if __name__ == '__main__':
N = int(input())
commands = [input() for _ in range(N)]
for output in execute_commands(commands):
print(output)