[Python-ideas] A sorted version of **kwargs

Arnaud Delobelle arnodel at gmail.com
Thu Jan 20 08:21:27 CET 2011

On 20 January 2011 04:29, Don Spaulding <donspauldingii at gmail.com> wrote:
> Hi there python-ideas!
> Does it bother anyone else that it's so cumbersome to instantiate an
> OrderedDict with ordered data?
>     >>> from collections import OrderedDict
>     >>> OrderedDict(b=1,a=2)
>     OrderedDict([('a', 2), ('b', 1)])          # Order lost. Boooo.
>     >>> OrderedDict([('b',1),('a',2)])
>     OrderedDict([('b', 1), ('a', 2)])
> Obviously, OrderedDict's __init__ method (like all other functions) never
> gets a chance to see the kwargs dict in the order it was specified.  It's
> usually faked by accepting the sequence of (key, val) tuples, as above.  I
> personally think it would be nice to be able to ask the interpreter to keep
> track of the order of the arguments to my function, something like:
>     def sweet_function_name(*args, **kwargs, ***an_odict_of_kwargs):
>         pass
> I'm not married to the syntax.  What do you think about the idea?

FYI this was discussed before on this list at least once:



More information about the Python-ideas mailing list