Let's suppose I have this simple array:
simple_list = [
('1', 'a', 'aa'),
('2', 'b', 'bb'),
('3', 'c', 'cc')
]
If we consider this list as a table, where columns are separated by comas and lines separated by tuples, I want to create a function that retrieves only the columns I want. for example, this function would look like something like this:
get_columns(array, tuple_columns_selector))
I want, for example, to collect only the first and third column out of it, in this case, it would return me another array with the new values:
if I do:
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 creating this get_columns function, please? Here's the code I've 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,)))
numpy.arraysget_columns(simple_list, (0,))return[('1'), ('2'), ('3')]? Since it should return a list of tuples...