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.
.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.
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.
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.
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.