I'm trying to add an extra column to a 2D array in Python but I'm stuck. I have a 2D array like below:
['000', '101']
['001', '010']
['010', '000']
['011', '100']
Then I swap 2 elements from the 2nd column and have something like this:
['000', '101']
['001', '000']
['010', '010']
['011', '100']
I want to take the last column right now and add it as the 3rd one like this:
['000', '101', '101']
['001', '010', '000']
['010', '000', '010']
['011', '100', '100']
But I only managed to get this:
['000', '101']
['001', '000']
['010', '010']
['011', '100']
101
000
010
100
I'm adding a column like this:
col = column(data,1)
data_res += col
I'm creating an array like this:
with open('data.txt', 'r') as f:
for line in f:
line_el = line.split()
data.append(line_el)
I'm swapping like this:
def swap(matrix, id_l, id_r):
matrix[id_l][1], matrix[id_r][1] = matrix[id_r][1],matrix[id_l][1]
return matrix
Any ideas?