BERKYT

Stack on python

Mar 23rd, 2022 (edited)
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. def convert_collection_to_stack(_collection):
  2.     return Stack(*_collection.values()) if isinstance(_collection, dict) else Stack(*_collection)
  3.  
  4.  
  5. class Stack:
  6.     def __init__(self, *args):
  7.         self._collection = list(args) if len(args) else []
  8.  
  9.     def push(self, item):
  10.         self._collection.append(item)
  11.  
  12.     def pop(self):
  13.         return self._collection.pop() if len(self._collection) else None
  14.  
  15.     def get_stack_as_list(self):
  16.         return self._collection
  17.  
Add Comment
Please, Sign In to add comment