python - dict.fromkeys return dictionary in reverse order from a list -
this question has answer here:
- how can sort dictionary key? 19 answers
i adding items of list dictionary keys equal none.
template_vars = headers[1:] kwargs = dict.fromkeys(template_vars)
when print values of both variables in terminal, follows.
{'type': 'nauman ahmad', 'name': 'cyborg'} ['name', 'type']
the order of dict reversed? how can in same order of list template_vars
because order matters me here?
dictionaries unordered. use ordereddict if order important:
from collections import ordereddict kwargs=ordereddict((k, none) k in template_vars)
Comments
Post a Comment