Python program to iterate over a dictionary.

In this python dictionary program, we will iterate over a dictionary using a for loop.

Steps to solve the program
  1. Take a dictionary as input.
  2. Use for loop to iterate over keys of the dictionary.
  3. With the help of the keys access the values of the respective keys.
  4. Print the output.
				
					D1 = {'food':'burger','type':'fast food'}

for val in D1:
    print(val,D1[val])
				
			

Output :

				
					food burger
type fast food
				
			

check whether a key exists in the dictionary or not.

create a dictionary in the form of (n^3)

Leave a Comment