def InternObject(obj): """Copies and interns strings in a recursive object.""" obj_cls = obj.__class__ if obj_cls is str: return sys.intern(obj) if obj_cls is str: return sys.intern(str(obj)) if obj_cls is dict: result = {} for k, v in list(obj.items()): k = InternObject(k) v = InternObject(v) result[k] = v return result if obj_cls is list: return [InternObject(x) for x in obj] return obj