[Python-ideas] A sorted version of **kwargs
donspauldingii at gmail.com
Thu Jan 20 08:33:43 CET 2011
On Thu, Jan 20, 2011 at 1:21 AM, Arnaud Delobelle <arnodel at gmail.com> wrote:
> 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.
> > personally think it would be nice to be able to ask the interpreter to
> > 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:
So it was. Thanks for that link. Am I to assume nothing ever came of that
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas