0

Now, you will have to implement the decoding function for boolean encodings. Your function decode_bool(encoding) -> bool will take a boolean lambda function and return the corresponding Python boolean value.

T = lambda a: lambda b: a
F = lambda a: lambda b: b

def decode_bool(encoding) -> bool:
    if bool(encoding) == 1:
            return True
    elif bool(encoding) == 0:
            return False

  print("=>", decode_bool(T))
  print("=>", decode_bool(F))
 
  • 1
    to determine what the lambda function returns, you must call it, e.g. in your function body `return encoding()`. `encoding` itself should return a boolean, so there's no need to cast the value. If `encoding` takes arguments, you must pass those when you call it, e.g., `return encoding(*args)`. (if you're unfamiliar with the "`*args`" syntax, [this](https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters) is a good source explaining it) – AJ Biffl Oct 31 '21 at 20:02

0 Answers0