Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




popitem( ) FUNCTION


The 'popitem( )' Function is used to remove the last inserted element from the Dictionary.


Note : Before version 3.7 'popitem( )' Function used to remove any random element from the 'Dictionary'.

Example :


x = {
    5 : "Is a Number", 
    "John": "Is a Name", 
    "Python": "Is a Language"
}
x.popitem()
print(x)


Output :



  {5: 'Is a Number', 'John': 'Is a Name'}

So, in the above code we have created a 'Dictionary' using braces '{ }' and 'Key' and 'Value' pairs.


x = {
    5 : "Is a Number", 
    "John": "Is a Name", 
    "Python": "Is a Language"
}

And initialised to the variable 'x'.


java_Collections

Now, we are supposed to delete the last inserted element. And the last inserted element is,


java_Collections

So, we have used the 'popitem( )' to delete it.


x.popitem( )

And initialised to the variable 'x'.


java_Collections

And we get the below output,


Output :



  {5: 'Is a Number', 'John': 'Is a Name'}