Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 15, 2020 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/eb7655fa0118fe9880a4dbae24d80e27 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/eb7655fa0118fe9880a4dbae24d80e27 to your computer and use it in GitHub Desktop.
d1={'a':1,'b':2,'c':3}
#removes and returns the last inserted item in the dictionary
print (d1.popitem())#Output:('c', 3)
from collections import OrderedDict
d1=OrderedDict({'a':1,'b':2,'c':3})
# by default,removes and returns the last inserted item in the OrderedDict
print (d1.popitem())#Output:('c', 3)
#if last=False,removes and returns the first inserted item in the OrderedDict.
print (d1.popitem(last=False))#Output:('a', 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment