I have two 2D lists which are A and B. List A has 3 rows with 2 columns while list B has 3 rows with 5 columns.
A=[[1,2],[3,4],[5,6]]
B=[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]
C=[]
And I would like to combine list A and list B to a new list called C corresponding to the row index. Such that the values in C[0] will be values in A[0] and values in B[0] so that C[0]=[1,2,1,2,3,4,5]
The expected combined list C:
C=[[1,2,1,2,3,4,5],[3,4,6,7,8,9,10],[5,6,11,12,13,14,15]]
And this is my work:
import numpy as np
A=[[1,2],[3,4],[5,6]]
B=[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]
C=[0,0,0]
for i in range(0,3):
C[i]=A[i],B[i]
But when I print out the list C, I find that it is different from I expected which looks like this:
[([1, 2], [1, 2, 3, 4, 5]), ([3, 4], [6, 7, 8, 9, 10]), ([5, 6], [11, 12, 13, 14, 15])]
Since I am a beginner of Python, I am not familiar with such 2D list operation, how can I achieve the expected result list C? Thank you for watching this post and answering my question.