A dict-like class that uses transformed keys <p>I'd like a dict-like class that transparently uses transformed keys on lookup, so that I can write</p> <pre><code>k in d # instead of f(k) in d d[k] # instead of d[f(k)] d.get(k, v) # instead of d.get(f(k), v) </code></pre> <p>etc. (Imagine for example that <code>f</code> does some kind of canonicalization, e.g. <code>f(k)</code> returns <code>k.lower()</code>.)</p> <p>It seems that I can inherit from <code>dict</code> and override individual operations, but not that there is a centralized spot for such transformation that all keys go through. That means I have to override all of <code>__contains__</code>, <code>__getitem__</code>, <code>get</code>, and possibly <code>__missing__</code>, etc. This gets too tedious and error-prone, and not very attractive unless this overhead outweighs that of manually substituting <code>f(k)</code> for every call on a plain <code>dict</code>.</p>