Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

(ii) Pop_element(): It pops the objects from the stack and displays them. Also, the function should display “Stack Empty” when there are no elements in the stack.

For example: If the nested list contains the following data:

BList=[["The Alchemist", "Paulo Coelho", 250],

["Animal Farm", "George Orwell", 150],

["The Da Vinci Code", "Dan Brown", 350],

["Harry Potter", "J.K. Rowling", 400],

["The Kite Runner", "Khaled Hosseini", 270],

["The Catcher in the Rye", "J.D. Salinger", 200]]

The stack should contain:

['The Alchemist', 'Paulo Coelho'], 

['Animal Farm', 'George Orwell'], 

['The Catcher in the Rye', 'J.D. Salinger']

The output should be:

['The Catcher in the Rye', 'J.D. Salinger']

['Animal Farm', 'George Orwell']

['The Alchemist', 'Paulo Coelho']

Stack Empty

Answer:

Answer by student

Function in Python that pops and displays the elements from a stack until it is empty - Teachoo.png

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.