Skip to content

Instantly share code, notes, and snippets.

Created Jul 11, 2020
What would you like to do?
# creating dictionary
d = {'name': 'karthi',
'age': 7,
'city': 'chennai',
#Returns reversed key iterator object
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
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
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