In this python dictionary program, we will Initialize a dictionary with default values
Steps to solve the program
- Take a list of keys as input and create a dictionary to set the default values for those keys.
- Create an empty list.
- 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}}