I have this function that can append the first three columns of data to a new empty list. Example output is:
['red', 'blue', 'green', 'yellow', 'purple', 'black']
I would like to enclose every two elements of this list in its own list i.e.
[['red', 'blue'], ['green', 'yellow'], ['purple', 'black']]
How can I do this? Thanks.
def selection_table(table):
atts = [1,2,3]
new_table = []
for row in table:
for i in range(len(new_atts)):
new_table.append(row[atts[i]])
return new_table