Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution in Clear category for Letter Queue by suic
def letter_queue(commands):
result = ""
for command in commands:
cmd = command.split(" ")
if cmd[0] == "PUSH":
result += cmd[1]
elif cmd[0] == "POP":
if not len(result) == 0:
result = result[1:]
return result
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"
July 9, 2014