Suppose I have this simple array:
simple_list = [ ('1', 'a', 'aa'), ('2', 'b', 'bb'), ('3', 'c', 'cc') ]
If we look at this list as a table where the columns are separated by lumps and rows separated by tuples, I want to create a function that retrieves only the columns that I want. for example, this function will look something like this:
get_columns(array, tuple_columns_selector))
For example, I want to collect only the first and third columns from it, in this case it will return another array with new values ββto me:
if:
get_columns(simple_list, (0,2)) get_columns(simple_list, (0,))
it will return something like:
[('1', 'aa'), ('2', 'bb'), ('1', 'cc')] [1, 2, 3]
And so on. Could you help me create this get_columns function please? Here is the code I tried:
def get_columns(arr, columns): result_list = [] for ii in arr: for i in columns: result_list.append(ii[i]) return result_list to_do_list = [ ('Wake Up', True), ('Brush Teeh', True), ('Go to work', True), ('Take a shower', True), ('Go to bed', False) ] print(get_columns(to_do_list, (0,)))