Reputation: 327
For example if I have:
a = [[[1, 1, 10], [148, 191, 203]],
[[133, 100], [19, 34]],
[[230, 200], [44, 68]]]
I would like to turn "a" it into:
[(1,148), (1,191), (10,203), (133,19), (100,34), (230,44), (200,68)]
Basically within each inner list I have a list of x values and a list of y values and I would like to pair them together. So a[0][0][0]
and a[0][1][0]
would be a pair. Is there a simple way that I would be able to do this? Thanks!
Upvotes: 1
Views: 975
Reputation: 147146
You can use zip
to put together each pair of lists into a list of tuples:
a = [[[1, 1, 10], [148, 191, 203]],
[[133, 100], [19, 34]],
[[230, 200], [44, 68]]]
print([z for x, y in a for z in zip(x, y)])
Output:
[(1, 148), (1, 191), (10, 203), (133, 19), (100, 34), (230, 44), (200, 68)]
Upvotes: 1