SlideShare a Scribd company logo
Data structures are “containers” that organize and group data according to type. The data structures differ
based on mutability and order.
The basic Python data structures in Python include list, set, tuples, and dictionary.
Each of the data structures is unique in its own way.
Stacks in Python will be made using
lists as per CBSE syllabus
List
It is a collections of items and each item has its own index value.
Index of first item is 0 and the last item is n-1.Here n is number of items in a list.
list1 = ['English', 'Hindi', 2022, 2021];
list2 = [23, 20, 32, 49, 52 ];
Indexing of list
0 1 2 3
['English', 'Hindi', 2022, 2021]
-5 -4 -3 -2 -1 Negative indexing
[23, 20, 32, 49, 52]
Positive
indexing
Accessing Elements of a list
Consider a list
list3 = ["sub1", "sub2", "sub3", "sub4"];
list3 = ["sub1", "sub2", "sub3", "sub4"];
print("n using positive indexing" )
print(list3[0],"n")
print(list3[1],"n")
print(list3[2],"n")
print("n using negative indexing" )
print(list3[-1],"n")
print(list3[-2],"n")
print(list3[-3],"n")
Output
Accessing elements of a list using loop
list3 = ["sub1", "sub2", "sub3", "sub4"];
for i in range(0, len(list3)):
print(list3[i])
In the above code range method is going from 0 to length-1 of the list.
So if length is 4 then range is going from 0 to 3
For list operations we can access elements from any index.
We can access from any direction
A stack is a linear data structure in which all the insertion
and deletion of data or you can say its values are done at
one end only, rather than in the middle.
That one position is
Now let us understand How to implement stack in Python using Lists
Applications of Stack
• Expression Evaluation: It is used to evaluate prefix, postfix and infix
expressions.
• Expression Conversion: It can be used to convert one form of
expression(prefix,postfix or infix) to one another.
• Parenthesis Checking: Stack is used to check the proper opening and
closing of parenthesis.
• String Reversal: It can be used to reverse a string.
• Function Call: Stack is used to keep information about the active functions
or subroutines.
Using List as Stack in Python
The concept of Stack implementation is easy in Python , because it
support inbuilt functions (append() and pop()) for stack
implementation.
By Using these functions make the code short and simple for stack
implementation.
To add an item to the top of the list, i.e., to push an item, we use
append() function and to pop out an element we use pop() function.
These functions work quiet efficiently and fast in end operations.
Stack interactive
program
Menu driven code for
stack operation

More Related Content

Similar to Stacks in Python will be made using lists.pdf

set.pptx
set.pptxset.pptx
set.pptx
satyabratPanda2
 
trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptx
Tapaswini14
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
ShreyasLawand
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
UsriDevi1
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
ASRPANDEY
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
ToniyaP1
 
Python for beginners
Python for beginnersPython for beginners
Python for beginners
Ali Huseyn Aliyev
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
Nguync91368
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
MeghaKulkarni27
 
Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
Python lists
Python listsPython lists
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
Bharati Vidyapeeth COE, Navi Mumbai
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
MeghaKulkarni27
 
Data structure Assignment Help
Data structure Assignment HelpData structure Assignment Help
Data structure Assignment Help
JosephErin
 

Similar to Stacks in Python will be made using lists.pdf (20)

set.pptx
set.pptxset.pptx
set.pptx
 
trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
Ch-8.pdf
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
 
Python for beginners
Python for beginnersPython for beginners
Python for beginners
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
Python data type
Python data typePython data type
Python data type
 
Python lists
Python listsPython lists
Python lists
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 
Data structure Assignment Help
Data structure Assignment HelpData structure Assignment Help
Data structure Assignment Help
 

More from DeeptiMalhotra19

Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
DeeptiMalhotra19
 
Newsletter june 2022.pdf
Newsletter june 2022.pdfNewsletter june 2022.pdf
Newsletter june 2022.pdf
DeeptiMalhotra19
 
Newsletter of May -2022
Newsletter of May  -2022Newsletter of May  -2022
Newsletter of May -2022
DeeptiMalhotra19
 
Newsletter- Hindi Subject
 Newsletter- Hindi Subject Newsletter- Hindi Subject
Newsletter- Hindi Subject
DeeptiMalhotra19
 
KINDERGARTEN NEWSLETTER 2022
KINDERGARTEN NEWSLETTER 2022    KINDERGARTEN NEWSLETTER 2022
KINDERGARTEN NEWSLETTER 2022
DeeptiMalhotra19
 
Science Newsletter
Science NewsletterScience Newsletter
Science Newsletter
DeeptiMalhotra19
 
Maths Newsletter
Maths NewsletterMaths Newsletter
Maths Newsletter
DeeptiMalhotra19
 
Newsletter - English
Newsletter - English Newsletter - English
Newsletter - English
DeeptiMalhotra19
 

More from DeeptiMalhotra19 (8)

Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
 
Newsletter june 2022.pdf
Newsletter june 2022.pdfNewsletter june 2022.pdf
Newsletter june 2022.pdf
 
Newsletter of May -2022
Newsletter of May  -2022Newsletter of May  -2022
Newsletter of May -2022
 
Newsletter- Hindi Subject
 Newsletter- Hindi Subject Newsletter- Hindi Subject
Newsletter- Hindi Subject
 
KINDERGARTEN NEWSLETTER 2022
KINDERGARTEN NEWSLETTER 2022    KINDERGARTEN NEWSLETTER 2022
KINDERGARTEN NEWSLETTER 2022
 
Science Newsletter
Science NewsletterScience Newsletter
Science Newsletter
 
Maths Newsletter
Maths NewsletterMaths Newsletter
Maths Newsletter
 
Newsletter - English
Newsletter - English Newsletter - English
Newsletter - English
 

Recently uploaded

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 

Recently uploaded (20)

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 

Stacks in Python will be made using lists.pdf

  • 1. Data structures are “containers” that organize and group data according to type. The data structures differ based on mutability and order. The basic Python data structures in Python include list, set, tuples, and dictionary. Each of the data structures is unique in its own way.
  • 2. Stacks in Python will be made using lists as per CBSE syllabus List It is a collections of items and each item has its own index value. Index of first item is 0 and the last item is n-1.Here n is number of items in a list. list1 = ['English', 'Hindi', 2022, 2021]; list2 = [23, 20, 32, 49, 52 ]; Indexing of list 0 1 2 3 ['English', 'Hindi', 2022, 2021] -5 -4 -3 -2 -1 Negative indexing [23, 20, 32, 49, 52] Positive indexing
  • 3. Accessing Elements of a list Consider a list list3 = ["sub1", "sub2", "sub3", "sub4"]; list3 = ["sub1", "sub2", "sub3", "sub4"]; print("n using positive indexing" ) print(list3[0],"n") print(list3[1],"n") print(list3[2],"n") print("n using negative indexing" ) print(list3[-1],"n") print(list3[-2],"n") print(list3[-3],"n") Output
  • 4. Accessing elements of a list using loop list3 = ["sub1", "sub2", "sub3", "sub4"]; for i in range(0, len(list3)): print(list3[i]) In the above code range method is going from 0 to length-1 of the list. So if length is 4 then range is going from 0 to 3 For list operations we can access elements from any index. We can access from any direction
  • 5. A stack is a linear data structure in which all the insertion and deletion of data or you can say its values are done at one end only, rather than in the middle. That one position is Now let us understand How to implement stack in Python using Lists
  • 6. Applications of Stack • Expression Evaluation: It is used to evaluate prefix, postfix and infix expressions. • Expression Conversion: It can be used to convert one form of expression(prefix,postfix or infix) to one another. • Parenthesis Checking: Stack is used to check the proper opening and closing of parenthesis. • String Reversal: It can be used to reverse a string. • Function Call: Stack is used to keep information about the active functions or subroutines.
  • 7. Using List as Stack in Python The concept of Stack implementation is easy in Python , because it support inbuilt functions (append() and pop()) for stack implementation. By Using these functions make the code short and simple for stack implementation. To add an item to the top of the list, i.e., to push an item, we use append() function and to pop out an element we use pop() function. These functions work quiet efficiently and fast in end operations.
  • 8.
  • 10. Menu driven code for stack operation