In this python dictionary program, we will move items from one dictionary to another dictionary.
Steps to solve the program
- Take one dictionary as input and create another empty dictionary.
- Use for loop to iterate over input dictionary.
- Add values from the input dictionary to the empty dictionary.
- Print the output.
dict1 = {'name':'john','city':'Landon','country':'UK'}
dict2 = {}
temp = dict1.copy()
for val in temp:
v1 = dict1.pop(val)
dict2[val] = v1
print("dictionary 2 :", dict2)
print("dictionary 1 :", dict1)
Output :
dictionary 2 : {'name': 'john', 'city': 'Landon', 'country': 'UK'}
dictionary 1 : {}