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
In the tests,
In the samples below, the first and only line of the input
contains the elements of the list
Output
The function should return one tuple
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) |