JorgeHB
JorgeHB

Reputation: 103

Creating a list that contains sets of numbers from two different vectors

I have two vectors of numbers:

vector_a = (5,10,15,20,25)
vector_b = (6,11,16,21,26)

And I want to have a list that gathers the information in this way:

[[5,6], [10,11], [15,16], [20,21], [25,26]]

Can anyone give me a clue of how to achieve this?

Upvotes: 0

Views: 165

Answers (2)

s3dev
s3dev

Reputation: 9711

Wrapping the zip function in the list function will do just that:

list(zip(list_a, list_b))

Upvotes: 0

Buddy Bob
Buddy Bob

Reputation: 5889

You could use zip.

new = [list(x) for x in zip(vector_a,vector_b)]

output

[[5, 6], [10, 11], [15, 16], [20, 21], [25, 26]]

Upvotes: 1

Related Questions