Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
The popitem() Method | Dictionary
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set

bookThe popitem() Method

Dictionaries also have a popitem() method that removes and returns the last key-value pair.

12345678910111213
book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Removing the last key-value pair using popitem() popped_item = book.popitem() # Printing the updated dictionary and the removed pair print("Removed item:", popped_item) print("Updated dictionary:", book)
copy
Task
test

Swipe to show code editor

Use the popitem() method to remove the last added key-value pair from the book dictionary and print it.

Note

The popitem() method returns the removed pair as a tuple.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 8
toggle bottom row

bookThe popitem() Method

Dictionaries also have a popitem() method that removes and returns the last key-value pair.

12345678910111213
book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Removing the last key-value pair using popitem() popped_item = book.popitem() # Printing the updated dictionary and the removed pair print("Removed item:", popped_item) print("Updated dictionary:", book)
copy
Task
test

Swipe to show code editor

Use the popitem() method to remove the last added key-value pair from the book dictionary and print it.

Note

The popitem() method returns the removed pair as a tuple.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 8
toggle bottom row

bookThe popitem() Method

Dictionaries also have a popitem() method that removes and returns the last key-value pair.

12345678910111213
book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Removing the last key-value pair using popitem() popped_item = book.popitem() # Printing the updated dictionary and the removed pair print("Removed item:", popped_item) print("Updated dictionary:", book)
copy
Task
test

Swipe to show code editor

Use the popitem() method to remove the last added key-value pair from the book dictionary and print it.

Note

The popitem() method returns the removed pair as a tuple.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Dictionaries also have a popitem() method that removes and returns the last key-value pair.

12345678910111213
book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Removing the last key-value pair using popitem() popped_item = book.popitem() # Printing the updated dictionary and the removed pair print("Removed item:", popped_item) print("Updated dictionary:", book)
copy
Task
test

Swipe to show code editor

Use the popitem() method to remove the last added key-value pair from the book dictionary and print it.

Note

The popitem() method returns the removed pair as a tuple.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 8
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt