A. Using push() method which does not exist for Python lists
B. Using pop() method incorrectly
C. Stack should be initialized as a tuple, not list
D. Missing import statement for stack
Solution
Step 1: Check methods used on list
Python lists do not have a push() method; append() is used to add elements.
Step 2: Verify pop() usage
pop() is valid for lists and correctly used here.
Final Answer:
Using push() method which does not exist for Python lists -> Option A
Quick Check:
Python list push() does not exist [OK]
Hint: Use append(), not push(), to add in Python list [OK]
Common Mistakes:
Assuming push() is valid for Python lists
Thinking pop() needs arguments
Confusing list with stack module
5. Given a stack implemented as a Python list, which sequence of operations will reverse the order of elements in the stack? Assume initial stack is [1, 2, 3] where 3 is the top. Choose the correct sequence:
hard
A. Append elements to the stack again without popping
B. Use pop() repeatedly and append to the same stack without extra storage
C. Pop all elements into a new stack
D. Sort the stack list in ascending order
Solution
Step 1: Understand reversing stack by popping
Pop elements from original stack and push them into a new stack reverses order.
Step 2: Confirm other options
Appending without popping or sorting does not reverse stack order correctly.
Final Answer:
Pop all elements into a new stack -> Option C
Quick Check:
Two stacks pop/push reverses order [OK]
Hint: Use two stacks to reverse order [OK]
Common Mistakes:
Trying to reverse by sorting
Appending without popping
Using one stack without extra storage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.