Python program to initialize a dictionary with default values

In this python dictionary program, we will Initialize a dictionary with default values

Steps to solve the program
  1. Take a list of keys as input and create a dictionary to set the default values for those keys.
  2. Create an empty list.
  3. Use for loop to iterate over keys in the list and add those keys to the empty dictionary and set up their values as default values using another dictionary that we have created.
				
					Name = ['Virat','Rohit']
Defaults = {'sport':'cricket','salary':100000}
D1 = {}

for name in Name:
    D1[name] = Defaults
    
print(D1)
				
			

Output :

				
					{'Virat': {'sport': 'cricket', 'salary': 100000}, 'Rohit': {'sport': 'cricket', 'salary': 100000}}
				
			

create a flat list of all the values in a flat dictionary. 

delete a list of keys from a dictionary.

Leave a Comment