Python program to print a dictionary line by line.

In this python dictionary program, we will print a dictionary line by line.

Steps to solve the program
  1. Take a dictionary as input.
  2. Use for loop to iterate over keys and values of the dictionary using items().
  3. First, print the key.
  4. Using nested for loop iterate over keys and values in the value of the respective key.
  5. Print the key-value pair.
				
					dict1 = {'virat':{'sport':'cricket','team':'india'},
         'messi':{'sport':'football','team':'argentina'}}
for key, val in dict1.items():
    print(key)
    for k,v in val.items():
        print(k,":",v)
				
			

Output :

				
					virat
sport : cricket
team : india
messi
sport : football
team : argentina
				
			

get a product with the highest price from a dictionary.

convert a key value list dictionary into a list of lists.

Leave a Comment