This question already has an answer here:
Python dictionary, how to keep keys/values in same order as declared?
As mentioned in the comments, you need to use an
OrderedDict if you want to rely on the ordering of elements in your dictionary:
>>> from collections import OrderedDict >>> OrderedDict(zip(a, b)) OrderedDict([('abc', ''), ('def', ''), ('ghi', ['123', '456', '786', '989']), ('jkl', ''), ('mno', ['222', '888', '111', '333'])])
It can be accessed in the same way as a normal
>>> x = OrderedDict(zip(a, b)) >>> x['abc'] ''