Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 11, 2020 01:21
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/07cda1bfad55c6394af184173e95d664 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/07cda1bfad55c6394af184173e95d664 to your computer and use it in GitHub Desktop.
# 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