- 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())

25th Jul 2021, 2:12 AM
Tan Tingxi
3 Respostas
+ 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
25th Jul 2021, 2:54 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 1
Another way is def pop(self): return self.lists.pop() DHANANJAY PATEL
25th Jul 2021, 3:03 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
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())
5th Oct 2022, 2:39 PM
Ha Tan Duc