Move items from one dictionary to another.

In this python dictionary program, we will move items from one dictionary to another dictionary.

Steps to solve the program
  1. Take one dictionary as input and create another empty dictionary.
  2. Use for loop to iterate over input dictionary.
  3. Add values from the input dictionary to the empty dictionary.
  4. Print the output.
				
					D1 = {'name':'john','city':'Landon','country':'UK'}
D2 = {}

for val in D1:
    D2[val] = D1[val]

print(D2)
				
			

Output :

				
					{'name': 'john', 'city': 'Landon', 'country': 'UK'}
				
			

print the square of all values in a dictionary.

concatenate two dictionaries

Leave a Comment