import collections
class StrKeyDict(collections.UserDict):
    def __missing__(self,key):
        if isinstance(key,str):
            raise KeyError(key)
        return self[str(key)]

    def __contains__(self,key):
        return str(key) in self.data

    def __setitem__(self,key,item):
        self.data[str(key)] = item

s = StrKeyDict([('1','apple'),('2','banana')])
print(s[1])
print(s['2'])