Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the front of the dequeue.
DSA Python
from collections import deque queue = deque() queue.[1](10) print(list(queue))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of appendleft adds element to the end, not front.
Using pop or popleft removes elements instead of adding.
✗ Incorrect
The method appendleft adds an element to the front of the dequeue.
2fill in blank
mediumComplete the code to remove an element from the rear of the dequeue.
DSA Python
from collections import deque queue = deque([1, 2, 3]) removed = queue.[1]() print(removed) print(list(queue))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using popleft removes from the front, not the rear.
Using append or appendleft adds elements instead of removing.
✗ Incorrect
The pop method removes and returns the element from the rear of the dequeue.
3fill in blank
hardFix the error in the code to remove an element from the front of the dequeue.
DSA Python
from collections import deque queue = deque([5, 6, 7]) removed = queue.[1]() print(removed) print(list(queue))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop removes from the rear, not front.
Using append or appendleft adds elements instead of removing.
✗ Incorrect
popleft removes and returns the element from the front of the dequeue.
4fill in blank
hardFill both blanks to add 20 to the rear and remove from the front of the dequeue.
DSA Python
from collections import deque queue = deque([10, 15]) queue.[1](20) removed = queue.[2]() print(removed) print(list(queue))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of popleft removes from rear, not front.
Using appendleft adds to front, not rear.
✗ Incorrect
append adds to the rear, popleft removes from the front.
5fill in blank
hardFill all three blanks to add 5 to front, remove from rear, and then add 10 to rear.
DSA Python
from collections import deque queue = deque([1, 2, 3]) queue.[1](5) removed = queue.[2]() queue.[3](10) print(removed) print(list(queue))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using popleft instead of pop removes from front, not rear.
Using append instead of appendleft adds to rear, not front.
✗ Incorrect
appendleft adds to front, pop removes from rear, append adds to rear.