forked from techstay/python-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletter_queue.py
More file actions
19 lines (16 loc) · 722 Bytes
/
letter_queue.py
File metadata and controls
19 lines (16 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def letter_queue(commands):
queue = []
for command in commands:
if command == 'POP':
if len(queue) > 0:
queue.pop(0)
else:
queue.append(command.split(' ')[1])
return ''.join(queue)
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert letter_queue(("PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T")) == "DOT", "dot example"
assert letter_queue(("POP", "POP")) == "", "Pop, Pop, empty"
assert letter_queue(("PUSH H", "PUSH I")) == "HI", "Hi!"
assert letter_queue(()) == "", "Nothing"
print("All done? Earn rewards by using the 'Check' button!")