Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One list expression solution in Creative category for Letter Queue by HipJoy
def letter_queue(commands):
queue = []
[(queue and queue.pop(0)) if cmd == 'POP' else queue.append(cmd[-1]) for cmd in commands]
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"
Aug. 24, 2015