Python Pop Exercises Let’s check out some exercises that will help understand .pop() method better. Exercise 12-a: Python pop method of lists and dictionaries Pop the last item of the list below. lst=[11, 100, 99, 1000, 999] #Type your answer here. popped_item= print(popped_item) print(lst) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(popped_item,999,"popped_item checks") self.assertEqual(lst,[11, 100, 99, 1000],"lst checks") myTests().main() Hint 1 .pop() method can be used to remove an item of a list or a dictionary and return that value. So, you can assign it to another variable if you’d like. Hint 2 If you don’t put anything inside .pop() method’s parenthesis it will automatically pop the last item in a list.However, you can’t do this for dictionaries since they don’t have index orders. Solution popped_item = lst.pop() Exercise 12-b: Python pop method to remove last list item Remove "broccoli" from the list using .pop and .index methods. lst=["milk", "banana", "eggs", "bread", "broccoli", "lemons"] #Type your code here. item= print(lst, item) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(item,"broccoli","item checks") self.assertEqual(lst,["milk", "banana", "eggs", "bread", "lemons"],"lst checks") myTests().main() Hint 1 .index() method can be helpful to find the index of the item you’re looking for. Hint 2 You can pass the index number of the element to the .pop() method and it will remove it. Solution a=lst.index("broccoli")item=lst.pop(a) Exercise 12-c: Pop method also saves the item being removed Save Italy's GDP in a separate variable and remove it from the dictionary. GDP_2018={"US": 21, "China": 16, "Japan": 5, "Germany": 4, "India": 3, "France": 3, "UK": 3, "Italy": 2} #Type your answer here. italy_gdp= print(GDP_2018) print(italy_gdp, "trillion USD") ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(italy_gdp,2,"italy_gdp checks") self.assertEqual(GDP_2018,{"US": 21, "China": 16, "Japan": 5, "Germany": 4, "India": 3, "France": 3, "UK": 3},"GDP_2018 checks") myTests().main() Hint 1 In dictionaries, .pop() method will still work but it will require you to write the name of the key inside it. Solution italy_gdp = GDP_2018.pop("Italy")