问候,
有一本字典取代了结构switch..case:
def __insert_value_with_the_key(self, key, value):
switcher = {
'AAA': self.__call_func1(value),
'BBB': self.__call_func2(value),
'CCC': self.__call_func3(value),
}
switcher.get(key)
而除了字典之外,还有这3个功能:
def __call_func1(self, value)
self.aaa_hashmap[value] = True
def __call_func2(self, value)
self.bbb_hashmap[value] = True
def __call_func3(self, value)
self.ccc_hashmap[value] = True
我想摆脱这些功能,但是,唉,做这样的事情:
'AAA' : lambda : self.aaa_hashmap[value] = True
这是被禁止的!我if不想使用它(因为有超过 3 个函数,并且字典中只有一个值发生变化(例如self.aaa_hashmap))
你有什么建议?
或者