Builtin dict should be callable, since a dict defines a function

Bengt Richter bokr at oz.net
Thu Dec 19 21:04:05 EST 2002


I posted the suggestion in a thread  Re: case-insensitive and internationalized sort,
but it occurs to me that the principle is arguable from the abstract point of view.
I.e., a dict implements a function key -> value, so why not let it accept a normal
function arg list (i.e., the tuple) as the argument for its key -> value function?
It should be a pretty simple change to provide __call__(self, *args): return self[args]
under the hood, and let hashability chips fall where they will via [].

The idea came up thinking about passing a dict in place of a comparison function,
where it might be practical to build a dict of all printable character pair tuples
and set the values according to how you want them ordered in a sort.

Regards,
Bengt Richter



More information about the Python-list mailing list