Problem C
Revealing Truth
Write a function, list_to_bool_tuple(), that converts every element in a given list to a boolean and then returns a tuple consisting of these boolean elements.
Any value can be interpreted as a boolean in Python.
For example, the empty string (written as "") would be interpreted as False (for example by writing bool("")), while any other string would be
interpreted as True.
Any integers encountered should be converted to int, before being evaluated to their truth value.
The main file, which handles input and output, is already provided. - Please only submit your function definitions, without any code outside the functions!
Note: The function list_to_bool_tuple can receive a list, whose elements are either integers, strings, or a mix of both.
Input
The function recieves one list $\ell $ as a parameter.
In the tests, $\ell $ will
be a list of length $0 \leq |\ell
| \leq 1\, 000$. The elements of the list will be
strings. You may assume all characters in the input are
printable ASCII characters.
In the samples below, the first and only line of the input contains the elements of the list $\ell $ seperated by commas. The autograder will handle reading the input, splitting it on the commas and passing the resulting list as an argument to your function.
Output
The function should return one tuple $t$, the elements of list $\ell $ converted to booleans.
Sample Input 1 | Sample Output 1 |
---|---|
1,2,bla,42,52,,0,,t,, |
(True, True, True, True, True, False, False, False, True, False, False) |
Sample Input 2 | Sample Output 2 |
---|---|
0,,1,10,-1 |
(False, False, True, True, True) |