python - dict.fromkeys return dictionary in reverse order from a list -


this question has answer here:

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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -