Iterate Over Dictionaries in Python Using Keys() Function
(Last Updated On: 28/12/2022)
Python Program to Iterate Over Dictionaries Using Keys() Function
# Iterate Over Dictionaries in Python Using Keys() Function
# Access key using the build .keys()
countryAndCode = {
'India': 'IND',
'Afghanistan': 'AFG',
'Canada': 'CAN',
'Russia': 'RUS'
}
# we are using an in-build. keys() method
keys = countryAndCode.keys()
# print all the keys in the dictionary
print(keys)