Why are there no ordered dictionaries?

bonono at gmail.com bonono at gmail.com
Sun Nov 20 08:33:16 EST 2005


przemek drochomirecki wrote:
> i am not sure what is the purpose of having ordered dictionaries built in
> python, could u provide any examples?
>
> i use a contruction:
>     for x in sorted(d.keys())
>
By ordered dict, one usually wants order that is arbitary which cannot
be derived from the content, say insertion order(most ordered dict I
saw use this order).

I am writing a web applications(simple forms) which has a number of
fields. Each field naturally has a name and a number of
attributes(formatting etc.), like this :

d = {'a':{...}, 'b':{....}}

This dict would be passed to the Kid template system which would lay it
out into a HTML form. For quick and dirty forms, I don't want to code
each field individually in the HTML template but just from top to
bottom(or left to right for a table) with a for loop.

However, I still want to group certain fields together. This is my need
of an ordered dict. Or course, I can pass a list along with the dict
and loop over the list and retrieve value from the dict, but that would
mean another things to pass along. And given the constraint of Kid
where everything must be one-liner(expression, no block of code), it
makes thing a bit harder.




More information about the Python-list mailing list