In: Computer Science
Description of the Assignment: Write a Python program to create a deque and append few elements to the left and right, then remove some elements from the left, right sides and reverse the deque.
Please use the following comments in your python script:
# *************************************************
# COP3375
# Student's full name ( <<< your name goes here)
# Week 9: Assignment 1
# *************************************************
# Write your code below:
# Create a deque
# Print a deque
# Append to the left
# Print a deque
# Append to the right
# Print a deque
# Remove from the right
# Print a deque
# Remove from the left
# Print a deque
# Reverse the dequeue
# Print a deque
Sample Output - Your output should look like something similar to the following:
deque(['Red', 'Green', 'White'])
Adding to the left:
deque(['Pink', 'Red', 'Green', 'White'])
Adding to the right:
deque(['Pink', 'Red', 'Green', 'White', 'Orange'])
Removing from the right:
deque(['Pink', 'Red', 'Green', 'White'])
Removing from the left:
deque(['Red', 'Green', 'White'])
Reversing the deque:
deque(['White', 'Green', 'Red'])
# *************************************************
# COP3375
# Student's full name ( <<< your name goes here)
# Week 9: Assignment 1
# *************************************************
# Write your code below:
from collections import deque
queue = deque(['Red', 'Green', 'White']) # Create a deque
print(queue) # Print a deque
queue.appendleft('Pink') # Append to the left
print(queue) # Print a deque
queue.append('Orange') # Append to the right
print(queue) # Print a deque
queue.pop() # Remove from the right
print(queue) # Print a deque
queue.popleft() # Remove from the left
print(queue) # Print a deque
queue.reverse() # Reverse the dequeue
print(queue) # Print a deque