Hi there python-ideas!<div><br></div><div>Does it bother anyone else that it's so cumbersome to instantiate an OrderedDict with ordered data?</div><div><br></div><div><div> >>> from collections import OrderedDict</div>
<div> >>> OrderedDict(b=1,a=2)</div><div> OrderedDict([('a', 2), ('b', 1)]) # Order lost. Boooo.</div><div> >>> OrderedDict([('b',1),('a',2)])</div><div>
OrderedDict([('b', 1), ('a', 2)])</div></div><div><br></div><div>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:</div>
<div><br></div><div> def sweet_function_name(*args, **kwargs, ***an_odict_of_kwargs):</div><div> pass</div><div><br></div><div>I'm not married to the syntax. What do you think about the idea?</div>