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.
- برمجة
- برمجة بايثون
- 2021-04-16
- salsabeelalhams99111801528
الأجوبة
import collections
# Create a deque
deque_colors = collections.deque(["Red","Green","White"])
print(deque_colors)
# Append to the left
print("\nAdding to the left: ")
deque_colors.appendleft("Pink")
print(deque_colors)
# Append to the right
print("\nAdding to the right: ")
deque_colors.append("Orange")
print(deque_colors)
# Remove from the right
print("\nRemoving from the right: ")
deque_colors.pop()
print(deque_colors)
# Remove from the left
print("\nRemoving from the left: ")
deque_colors.popleft()
print(deque_colors)
# Reverse the dequeue
print("\nReversing the deque: ")
deque_colors.reverse()
print(deque_colors)أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال