[Python-ideas] A sorted version of **kwargs
rrr at ronadam.com
Fri Jan 21 05:59:07 CET 2011
On 01/20/2011 09:42 PM, Steven D'Aprano wrote:
> Hongbao Chen wrote:
>> Hey, guys
>> I must argue that make **kwargs sorted is really a terrible idea.
>> Please think that when user wants a unsorted **kwargs, how can he or she
>> bring the original unsorted dict back?
> Despite the subject line, this is not about a *sorted* dict, but about
> an *ordered* dict. The difference is that an ordered dict remembers the
> order that elements are given:
Yes, I was going to say that. :-)
Presumably there are either performance or space reasons why an unorderd
dictionary is better. (or both)
These concepts do overlap, presumably an order dict can be sorted in place,
rather than keeping a separate sorted list of keys. However, the orderd
dictionary in the collections module doesn't do that. You sort it by
sorting the items and then use those to create a new ordered dictionary.
Lately I've been thinking it may be useful to have access to a separate
self contained function-signature object. As a direct plug-in to functions
and methods, it may present some nice advantages when it comes to how
things fit together in python.
More information about the Python-ideas