Look up value in Django json object -


in django view have object

state_lookup = {"alabama":"al", "alaska":"ak", ... "wyoming":"wy"} 

how pass state name object , abbreviation in return?

python dictionaries can accessed in same way lists. here example.

state_lookup = {"alabama":"al", "alaska":"ak", ... "wyoming":"wy"} state = 'alabama' abbrev = state_lookup[state] # abbrev should 'al' 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -