- 1
How do I make a back button for a browser
I need to make a back button for a browser use stack. https://www.sololearn.com/learning/1159 class Browser: def __init__(self): self.links = [] def is_empty(self): return self.links == [] def push(self, link): self.links.insert(0, link) x = Browser() x.push('about:blank') x.push('www.sololearn.com') x.push('www.sololearn.com/courses/') x.push('www.sololearn.com/courses/JUMP_LINK__&&__python__&&__JUMP_LINK/') while not x.is_empty(): print(x.pop())
3 Antworten
+ 1
Add following member function
def pop(self):
       rv = self.lists[-1]
       self.lists = self.lists[:-1]
       return rv
it will helpful to complete code
DHANANJAY PATEL
+ 1
Another way is
def pop(self):
       return self.lists.pop()
DHANANJAY PATEL
0
class Browser:
    def __init__ (self):
      self.links = []  
  
    def is_empty(self):
      return self.links == []
  
    def push(self, link):
      self.links.insert(0, link)
    def pop(self):
       return self.links.pop(0)
  
x = Browser()
x.push('about:blank')
x.push('www.sololearn.com')
x.push('www.sololearn.com/courses/')
x.push('www.sololearn.com/courses/JUMP_LINK__&&__python__&&__JUMP_LINK/')
while not x.is_empty():
    print(x.pop())




