Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 15, 2020 04:57
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/9842687204900abc71e85388d24d0432 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/9842687204900abc71e85388d24d0432 to your computer and use it in GitHub Desktop.
from collections import OrderedDict
d3=OrderedDict({'a':1,'b':2,'c':3})
#reversed(OrderedDict) will return reversed iterator object over keys.
print (reversed(d3))#Output:<odict_iterator object at 0x00DBE028>
#converting iterator object to list.
print (list(reversed(d1)))#Output:['c', 'b', 'a']
k=d3.keys()
#Returns new view of ordered dictionary keys.
print (k)#Output:odict_keys(['a', 'b', 'c'])
#Returns reversed iterator over keys.Converting iterator to list object.
print (list(reversed(k)))#Output:['c', 'b', 'a']
i=d3.items()
#Returns new view of ordered dictionary items.
print (i)#Output:odict_items([('a', 1), ('b', 2), ('c', 3)])
#Returns reversed iteraator object over items. Converting iterator to list object.
print (list(reversed(i)))#Output:[('c', 3), ('b', 2), ('a', 1)]
v=d3.values()
#Returns new view of ordered dictionary values.
print (v)#Output:odict_values([1, 2, 3])
#Returns reversed iterator object over values.Converting iterator to list object
print (list(reversed(v)))#Output:[3, 2, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment