r/learnpython•
qspec02

Queue class with two lists

I am trying to write a class that functions as a queue using two lists. I know there are better ways to do this (like Lib/Queue), but I am hoping to learn a few things by doing it this way.

Here's what I have:

class Queue(list):
    def pop(self):
    tmp = []
    for i in range(len(self)):
        tmp.append(self.pop())
        res = tmp.pop()
    for tmp in range(len(l)):
        self.append(tmp.pop())
    return res

x = Queue()
x.append(5)
x.pop()  #Recursive error

The issue seems to be that I can't call pop() (and I'd assume other list functions) on self. But how do I access the data to do what I'm trying to do?

Posted Aug 17, 2017, 7:37 PM UTC

35
Loading comments…