Insert a key at the beginning of the dictionary.

In this python dictionary program, we will insert a key at the beginning of the dictionary.

Steps to solve the program
  1. Take a dictionary as input.
  2. Create a new dictionary of the key which you want to update.
  3. Now concatenate the new dictionary with the old dictionary using update().
  4. So, the new key will be the first key.
  5. Print the output.
				
					dict1 = {'course':'python','institute':'sqatools' }
dict2 = {'name':'omkar'}

dict2.update(dict1)

print(dict2)
				
			

Output :

				
					{'name': 'omkar', 'course': 'python', 'institute': 'sqatools'}
				
			

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

create a dictionary where keys are between 1 to 5 and values are squares of the keys.

Leave a Comment