Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 11, 2020 01:31
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/14875fdddcb1019d5bcb245ee4b48246 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/14875fdddcb1019d5bcb245ee4b48246 to your computer and use it in GitHub Desktop.
# creating dictionary
d = {'name': 'karthi',
'age': 7,
'city': 'chennai',
}
#Returns reversed key iterator object
k=d.keys()
print (reversed(k))#Output:<dict_reversekeyiterator object at 0x010C3BB8>
#converting iterator to list object
print (list(reversed(k)))#Output:['city', 'age', 'name']
#Returns reversed items iterator object
i=d.items()
print (reversed(i))#Output:<dict_itemiterator object at 0x00A1E028>
#looping through the iterator
for i in reversed(i):
print (i)
'''
('city', 'chennai')
('age', 7)
('name', 'karthi')
'''
#Return reversed values iterator object
v=d.values()
print (reversed(v))#Output:<dict_reversevalueiterator object at 0x01143BE0>
#converting iterator to list object
print (list(reversed(v)))#Output:['chennai', 7, 'karthi']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment