[Solved] Build a new dictionary from the keys of one dictionary and the values of another dictionary


What you are trying to do is impossible to do in any predictable way using regular dictionaries. As @PadraicCunningham and others have already pointed out in the comments, the order of dictionaries is arbitrary.

If you still want to get your result, you must use ordered dictionaries from the start.

>>> from collections import OrderedDict
>>> d1 = OrderedDict((('a',1), ('b',2), ('c', 3)))
>>> d2 = OrderedDict((('x',4), ('y',5), ('z', 6)))
>>> d3 = OrderedDict(zip(d1.keys(), d2.values()))
>>> d3
OrderedDict([('a', 4), ('b', 5), ('c', 6)])

1

solved Build a new dictionary from the keys of one dictionary and the values of another dictionary