Course Content
Python Data Structures
Python Data Structures
Popitem() Method
Dictionaries also have a popitem()
method that removes and returns the last key-value pair.
# Creating Dictionary numbers= {1: 'one', 2: 'two', 3: 'three', 5: 'five'} # Deleting a key using popitem() popped_element = numbers.popitem() print(numbers)
Task
Consider the dictionary below:
Remove the last three entries from the dictionary using the popitem()
method.
Thanks for your feedback!
Popitem() Method
Dictionaries also have a popitem()
method that removes and returns the last key-value pair.
# Creating Dictionary numbers= {1: 'one', 2: 'two', 3: 'three', 5: 'five'} # Deleting a key using popitem() popped_element = numbers.popitem() print(numbers)
Task
Consider the dictionary below:
Remove the last three entries from the dictionary using the popitem()
method.
Thanks for your feedback!
Popitem() Method
Dictionaries also have a popitem()
method that removes and returns the last key-value pair.
# Creating Dictionary numbers= {1: 'one', 2: 'two', 3: 'three', 5: 'five'} # Deleting a key using popitem() popped_element = numbers.popitem() print(numbers)
Task
Consider the dictionary below:
Remove the last three entries from the dictionary using the popitem()
method.
Thanks for your feedback!
Dictionaries also have a popitem()
method that removes and returns the last key-value pair.
# Creating Dictionary numbers= {1: 'one', 2: 'two', 3: 'three', 5: 'five'} # Deleting a key using popitem() popped_element = numbers.popitem() print(numbers)
Task
Consider the dictionary below:
Remove the last three entries from the dictionary using the popitem()
method.