I am fairly new to dictionaries, so this is probably a fairly basic question.
Let’s say I have two different dictionaries with similar elements.
Example:
Dictionary1 = {'Bob' : 1, 'Mary' : 2, 'Sue' : 3, 'George' : 4}
Dictionary2 = {'Bob' : 1, 'Sue' : 2, 'Jill' : 3, 'Isaac' : 4, 'George' : 5}
I want to be able to take the intersection of the two dictionaries and apply the indices of the first dictionary to the second. So I want an output that looks something like this:
DictionaryCombo = {'Bob' : 1, 'Sue' : 3, 'George' : 4}
Please excuse my formatting for my desired output, as I am not certain what it should look like, though I know that I want the key and value pairs of the intersection of the two dictionaries.
If you want to subset d1 so it only has elements present in d2
Or you mention apply, so did you want to update values in d2?
Or, if you really are starting with two lists (and not starting with dict’s):
If you have two lists, one of keys, and one of values, and wish to make them a
dict, then you can usezip: