Practice Deque Operations
Run a list of add and remove commands on both ends of a collections.deque and report what each remove returns.
The problem
Implement run_deque_commands(commands). Start with an empty double-ended queue and run the commands in order. Each command is one of: - ["append-right", value]: add value at the right end. - ["append-left", value]: add value at the left end. - ["pop-right"]: remove the value at the right end. - ["pop-left"]: remove the value at the left end. Return a list with one entry for every pop command, in order: the value that was removed, or None if the queue was empty. Example: [["append-right", 2], ["append-left", 1], ["pop-right"], ["pop-left"]] returns [2, 1].
Starter code
from collections import deque
def run_deque_commands(commands):
passPublic examples
commands = [["append-right", 2], ["append-left", 1], ["pop-right"], ["pop-left"]]gives[2, 1]commands = [["pop-left"], ["pop-right"]]gives[None, None]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
