Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Letter Queue by piter239
def letter_queue(commands):
q = []
for cmd in commands:
c, *d = cmd.split(' ')
if c == "PUSH":
q.append(*d)
elif c == "POP":
q = q[1:]
return ''.join(q)
if __name__ == '__main__':
print(letter_queue(["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"]))
#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"
April 23, 2020