class CaseInsensitiveDict(dict): def __setitem__(self, key, value): key = key.lower() dict.__setitem__(self, key, value) def __getitem__(self, key): key = key.lower() return dict.__getitem__(self, key) d = CaseInsensitiveDict() d["Python"] = "Easy" print d["PYTHON"] print d["python"]
Output:
Easy Easy
0 comments:
Post a Comment