why should dict not be callable?

georgeryoung at gmail.com georgeryoung at gmail.com
Tue Oct 17 21:25:46 CEST 2006


A couple of times recently I've come across this problem:  I have a
large list to sort and I need to the the "key=function" argument to
sort appropriately.  But I actually have the key mapping in a big
dictionary.  Now I have to make an intermediary function:

def key_fn(key):
   return key_dict[key]

If a dict were callable directly, this would be unnecessary.  Often the
small extra complexity and compute time is not important, but in
sorting a large list, it could be a significant difference.  Is there
some reason a subscriptable thing like a dict should *not* be callable?
 

-- George [nitpicking...]




More information about the Python-list mailing list