class KeyDict(defaultdict):

    def __missing__(self, key):
        return key
d = KeyDict()
print(d['b'])
print(list(d.keys()))
How to make a python dictionary that returns key for keys missing from the dictionary instead of raising KeyError?