Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an empty deque using Python's collections module.
DSA Python
from collections import deque my_deque = deque([1]) print(my_deque)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing None which causes error
✗ Incorrect
To create an empty deque, you pass an empty list [] to deque().
2fill in blank
mediumComplete the code to add an element 10 to the right end of the deque.
DSA Python
from collections import deque my_deque = deque([]) my_deque.[1](10) print(my_deque)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop or popleft which remove elements
Using appendleft which adds to the left end
✗ Incorrect
Use append to add an element to the right end of the deque.
3fill in blank
hardFix the error in the code to remove an element from the left end of the deque.
DSA Python
from collections import deque my_deque = deque([1, 2, 3]) removed = my_deque.[1]() print(removed) print(my_deque)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes from right end
Using remove which removes by value, not position
Using delete which is not a deque method
✗ Incorrect
Use popleft() to remove and return the element from the left end of the deque.
4fill in blank
hardFill both blanks to rotate the deque one step to the right.
DSA Python
from collections import deque my_deque = deque([1, 2, 3, 4]) my_deque.[1]([2]) print(my_deque)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of rotate
Using negative number to rotate right
✗ Incorrect
Use rotate(1) to move all elements one step to the right.
5fill in blank
hardFill all three blanks to create a deque, add 5 to the left, and remove from the right.
DSA Python
from collections import deque my_deque = deque([1]) my_deque.[2](5) removed = my_deque.[3]() print(removed) print(my_deque)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting with empty deque instead of list
Using append instead of appendleft
Using popleft instead of pop
✗ Incorrect
Start with deque([1, 2, 3]), add 5 to the left with appendleft, then remove from right with pop.