In this python dictionary program, we will insert a key at the beginning of the dictionary.
Steps to solve the program
- Take a dictionary as input.
- Create a new dictionary of the key which you want to update.
- Now concatenate the new dictionary with the old dictionary using update().
- So, the new key will be the first key.
- Print the output.
dict1 = {'course':'python','institute':'sqatools' }
dict2 = {'name':'omkar'}
dict2.update(dict1)
print(dict2)
Output :
{'name': 'omkar', 'course': 'python', 'institute': 'sqatools'}