S
S
sbh2020-04-24 13:56:05
Python
sbh, 2020-04-24 13:56:05

How to make 1 from several lists?

There are several lists with data:
1) a[1,2,3]
2) b[blue, green, red]
3) c[11,22,33]

At the output, you need to get a structure like
d [1,blue,11] [2,green,22][3,red,33]

What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-04-24
@sbh

list(zip(a, b, c))

S
Sergey Grebennikov, 2020-04-25
@SergeyGrebennikov

The option d = list(zip(a, b, c))will create a list of tuples (turble). But when you try to change something in some element of the list, for example d[0][2] = 12, you will get the error "'tuple' object does not support item assignment"
As an option to get a list of lists

d =  for i in range(min(len(a), len(b), len( c)))]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question