Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 11, 2020
Embed
What would you like to do?
# creating dictionary
d = {'name': 'karthi',
'age': 7,
'city': 'chennai',
}
#Returns key iterator object
k=d.keys()
print (iter(k))#Output:<dict_keyiterator object at 0x00A1E028>
#converting iterator to list object
print (list(iter(k)))#Output:['name', 'age', 'city']
#Returns items iterator object
i=d.items()
print (iter(i))#Output:<dict_itemiterator object at 0x00A1E028>
#looping through the iterator
for i in iter(i):
print (i)
'''
('name', 'karthi')
('age', 7)
('city', 'chennai')
'''
#Return values iterator object
v=d.values()
print (iter(v))#Output:<dict_valueiterator object at 0x00A1E028>
#converting iterator to list object
print (list(iter(v)))#Output:['karthi', 7, 'chennai']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment