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

John Roth johnroth at ameritech.net
Fri Dec 20 17:33:43 EST 2002


"Bengt Richter" <bokr at oz.net> wrote in message
news:atttql$ouf$0 at 216.39.172.122...
> 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.

Let's see if I understand this properly. What you're suggesting is a
syntax
that would let me do multiple lookups in a dictionary. Essentially
something
like <dict>.getlist(<list of keys>) returning a list of values?

I'm not certain where this would be all that useful, but if it is, I'd
be much
more likely to support it as a member function than as a wierd
side-effect
of calling the dictionary.

John Roth


>
> Regards,
> Bengt Richter





More information about the Python-list mailing list