Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 15, 2020 04:15
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/11affa56702c09fe117a7126ce556e56 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/11affa56702c09fe117a7126ce556e56 to your computer and use it in GitHub Desktop.
from collections import OrderedDict
d1=OrderedDict({'a':1,'b':2,'c':3})
d1.move_to_end('b')
#It moves the key -'b' to the end.By default last=True
print (d1)#Output:OrderedDict([('a', 1), ('c', 3), ('b', 2)])
d1.move_to_end('c',last=False)
#Since last=False, it moves the key 'c' to beginnning of ordered dictionary.
print (d1)#Output:OrderedDict([('c', 3), ('a', 1), ('b', 2)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment