Output Sorted Python Dict Within Django Template
I got a python dict, that looks like the following (Important informations were replaced with 'xxx' due to privacy reasons). I would like to display this dict within a django templ
Solution 1:
Dictionaries are unsorted.
You will need to convert your dict to a nested list in the view: the easiest way would be just to call sorted(bdays_all.items()).
Solution 2:
You also could create a new dictionary with sorted keys in your view:
dictio = {'a': 'orange', 'c':'apple', 'b': 'bannana'}
di = {}
for key in sorted(dictio.iterkeys()):
di[key] = dictio[key]
whit the result:
di = {'a': 'orange', 'b': 'bannana', 'c': 'apple'}
Post a Comment for "Output Sorted Python Dict Within Django Template"