[Python-ideas] Ordered storage of keyword arguments

Stephen J. Turnbull stephen at xemacs.org
Fri Oct 29 08:28:07 CEST 2010

Chris Rose writes:

 > I'm hard pressed to see how an ordered dict and a dict should be
 > expected to differ by such a degree; in every particular they behave
 > the same, except in the case of the OrderedDict you specify your
 > initial parameters in tuples? Eugh.

But initializing a dict with "dict(a=1, b=2)" is purely an accidental
convenience based on the fact that a **kw argument is implemented as a
dict.  I find that syntax a bit disconcerting, actually, though it's
natural on reflection.

If you think of odict as an (efficient) associative list (order is
primary function, random access via keys secondary), rather than an
ordered mapping (random access via keys is primary function, order
secondary) then the syntaxes

    ['a' : 1, 'b' : 2, 'c' : 3]    # create an odict

(surely that has been suggested before!) and

    def foo([**kw]):               # pass kw as an odict

are suggestive.  I don't know whether either would be parsable by
Python's parser, and I haven't thought about how the latter would deal
with positional or kw-only arguments.

More information about the Python-ideas mailing list