A dictionary contains the pair of the keys & values (represents key : value), a dictionary is created by providing the elements within the curly braces ({}), separated by the commas.
In a dictionary, the keys need to be unique but the values mapped can have duplicate values.
And using the keys, we can find and replace values mapped to it.
We have two dictionaries, one with values and another consisting of the key-value pairs. We need to print the dictionary after replacing values for keys present in replace dictionary.
Example:
Dictionary:
['scala':8, 'Javascript': 7, 'Python':1, 'C++':5, 'Java':3]
ReplaceDictionary:
['Javascript': 2, 'C++': 9]
UpdatedDictionary:
['scala':8, 'Javascript': 2, 'Python':1, 'C++':9, 'Java':3]
Program to replace dictionary value for the given keys in another dictionary
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer