Reputation: 13
I am new to Python and I would like to combine two arrays. I have two arrays: A
and B
and would like to get array C
as follows:
A = [1, 2, 3, 4, 5]
B = [6, 7, 8, 9, 10]
Result array:
C = [(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)]
Upvotes: 0
Views: 570
Reputation: 3784
Without any dependency:
>>> A = [1, 2, 3, 4, 5]
>>> B = [6, 7, 8, 9, 10]
>>> C = [(A[i], B[i]) for i in range(len(A))]
>>> C
[(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)]
Upvotes: 0
Reputation: 73450
Use zip
, the built-in for pairwise iteration:
C = list(zip(A, B))
Note that you are not concatenating the two lists.
Upvotes: 2