-
-
Save IndhumathyChelliah/9842687204900abc71e85388d24d0432 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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