Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Letter Queue by Mahoter
def letter_queue(commands):
que = []
res = ""
for order in commands:
if order[0:4] == 'PUSH':
que += [order[len(order)-1]]
if order[0:3] == 'POP' and len(que)>0:
que.pop(0)
for lett in que:
res += str(lett)
return res
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"
Jan. 17, 2016