Iterate Over Dictionaries in Python Using for Loop

(Last Updated On: 28/12/2022)

Iterate over dictionaries in python using for loop without using a key() function

Python Program to Iterate Over Dictionaries Using for Loop

# Iterate Over Dictionaries in Python Using for Loop
# Access key without using a key()

countryAndCode = {
	'India': 'IND',
	'Afghanistan': 'AFG',
	'Canada': 'CAN',
	'Russia': 'RUS'
}

print('List of given Country:\n')

# Iterating over dictionaries using 'for' loops for iterating our keys
for Country in countryAndCode:
	# printing all the keys present in the Dictionary.
	print(Country)

Output:

List of given Country:

India
Afghanistan
Canada
Russia

Leave a Reply

Your email address will not be published. Required fields are marked *