Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
dictionary + lambda as a replacement for switch solution in Clear category for Boolean Algebra by kdim
def boolean(x, y, operation):
result = { # dictionary + lambda as a replacement for switch
'conjunction': lambda x, y: x and y, #
'disjunction': lambda x, y: x or y, #
'exclusive': lambda x, y: int(x != y), #
'equivalence': lambda x, y: int(x == y), #
'implication': lambda x, y: y if x else 1 #
}[operation](x, y)
return result
Jan. 27, 2021
Comments: