扩展字典的类

class ValueDict(dict):
    def __init__(self,*args,**kargs):
        super().__init__(*args,**kargs)
    def getValueByKey(self,val):
        result = []
        for key,values in self.items():
            if values == val:
                result.append(key)
        return result
new = ValueDict(name="shun",name2="shun",name3="shunshun")
print(new.getValueByKey("shun"))

 

posted @ 2023-02-15 22:00  朵朵奇fa  阅读(8)  评论(0编辑  收藏  举报