-
-
Save IndhumathyChelliah/07cda1bfad55c6394af184173e95d664 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
# 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