Here's an easy algorithm question about stack and queue, could anyone please help me to look at what's wrong with my code?
Implement a queue with two stacks. The declaration of the queue is as follows. Implement its two functions appendTail and deleteHead, which perform the functions of inserting an integer at the end of the queue and deleting an integer at the head of the queue, respectively. (If there are no elements in the queue, the deleteHead operation returns -1 )
text
class CQueue(object):

    def __init__(self) -> None:
        self.__stackA = [] 
        self.__stackB = [] 

    def appendTail(self, val: int) -> None:
        self.__stackA.append(val)
    
    def deleteHead(self) -> int:
        if self.__stackB == 0:
            if self.__stackA == 0:
                return -1
            else:
                self.__stackB.append(self.__stackA.pop())
                return self.__stackB.pop()
        else:
            return self.__stackB.pop()

My code is above. I tried to separate the situation into: 1) B = 0, A = 0 (returns -1); 2) B = 0, A != 0 (transferring the elements from A to B), and 3) B != 0 (directly popping the front element)
The correct input and output should be:
input:
["CQueue","appendTail","deleteHead","deleteHead","deleteHead"] [[],[3],[],[],[]]
output:
[null,null,3,-1,-1]
Thank you for paying attention to the question and would be appreciated if you could help.

Algorithm question - Stack and Queue - easy
There are two issues:

Comparing a list with 0 is not really useful, as that will never be true. To test whether a list is empty, you can use the not self.__stackA or len(self.__stackA) == 0, or a combination of the two.

When stack B is empty, but stack A has values, you should not transfer one element from the top of stack A to stack B, but should transfer all its elements, so that the element that was at the bottom of stack A gets to be the top element of stack B.


With those two remarks taken care of, your code would look like this:
class CQueue(object):

    def __init__(self) -> None:
        self.__stackA = [] 
        self.__stackB = [] 

    def appendTail(self, val: int) -> None:
        self.__stackA.append(val)
    
    def deleteHead(self) -> int:
        if not self.__stackB:  # don't compare with 0
            if not self.__stackA:
                return -1
            else:
                while self.__stackA:  # Transfer ALL elements
                    self.__stackB.append(self.__stackA.pop())
                return self.__stackB.pop()
        else:
            return self.__stackB.pop()

You can also avoid some duplication of code:
    def deleteHead(self) -> int:
        if not self.__stackB:
            while self.__stackA:
                self.__stackB.append(self.__stackA.pop())
            if not self.__stackB:  # Still nothing there...
                return -1
        return self.__stackB.pop()  # Common action when there is data

Remark: I would have expected the stacks to be created with a specific class, because when you create them as standard lists, there is no reason why you could do non-stacky things with them, like reversing them, etc, which obviously is not to be allowed in this challenge.
