A Python self invoking dict func. In the example below, whatever `self.mode`, it will call the two named functions if the input to `.get()` is in the dict keys(), else the lambda: None :)
{ "input": self.input_mode, "output": self.output_mode }.get(self.mode, lambda: None)()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def g(): print("hooo") | |
... | |
>>> g() | |
hooo | |
>>> def h(): print("boo") | |
... | |
>>> {'i': g, 'k': h}.get('i', lambda: None)() | |
hooo | |
>>> {'i': g, 'k': h}.get('f', lambda: None)() | |
>>> |