I already said this in the comments, but itβs important to understand that this is not what TransformDict should do. Therefore, you can subclass it with a special implementation for keys :
class MyTransformDict(TransformDict): def keys(self): return map(self.transform_func, super().keys())
Depending on your version of Python, you will probably need to use list() around map (Python 3) or provide arguments for super : super(TransformDict, self) (Python 2). But this should illustrate the principle.
As @Rawing noted in the comments, there will be more methods that won't work as expected, i.e. __iter__ , items and probably also __repr__ .
source share