Implement stack in Python using list | step by step explanation

Pubblicato il: 20 settembre 2021
sul canale di: Joey'sTech
2,438
24

In this video, you will learn how to implement a stack in python.

A stack is a data structure in which elements are pushed inside the stack from the top and popped out from the top as well.

Stack stores elements on a LIFO basis (Last-In-First-Out) basis.

Stack is a data structure not available in Python hence, in this video I have implemented it using a list.

This is one of the frequently asked Python interview questions as well so you might want to follow along with me.

----------------------------------------------------
Important explanations
----------------------------------------------------
self.stack[ len(self.stack)-1 ]
len() determines the length of the stack which in this program is a list. Subtracting 1 determines the last index


range(len(self.stack)-1,-1,-1)
The first parameter of the range function determines the last index of the list.
The second parameter is -1 the number you want your loop to run because range considers the final element as +1 to the integer given.
The 3rd parameter gives the step in which the loop decrements.
Note - the last 2 parameters are negative because the loop is decrementing.


[ Github link ]
https://github.com/joeystech2020/pyth...

------------------
Also, Watch
-------------------
How to install Python on Mac
   • How to install Python on Mac | Python...  

How to install Pycharm on Mac
   • How to install PyCharm on Mac | Step ...  


In questa pagina del sito puoi guardare il video online Implement stack in Python using list | step by step explanation della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Joey'sTech 20 settembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 2,438 volte e gli è piaciuto 24 spettatori. Buona visione!