Skip to content
Unknown's avatar

Welcome to CodesWithSayan

#Eat#Sleep#Code#Repeat

  • Twitter
  • Facebook
  • Instagram
  • Twitter
  • Contact

Tag: data_structures

How to implement a Stack in Python

class Stack():
    def __init__(self):
        self.items = []

    def push(self, item):
        self.items.append(item)				

    def pop(self):
        return self.items.pop()
    
    def is_empty(self):
        return self.items == []
    
    def peek(self):
        if not self.is_empty():
            return self.items[-1]
        
    def get_stack(self):
        return self.items

s = Stack()
print(s.is_empty())
Sayan Dey Uncategorized Leave a comment July 30, 2020 1 Minute
Blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
    • Welcome to CodesWithSayan
    • Already have a WordPress.com account? Log in now.
    • Welcome to CodesWithSayan
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
Design a site like this with WordPress.com
Get started