This should use `type(key)` as index. You should also try to catch the possible IndexError exception and translate that error to something more reasonable like `"Unsupported key type %s" % (type(key),)`