Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to merge two lists in python?

I have the following two lists:

lista = ['a', 'b']
listb = ['c', 'd']

And I want the output list like this:

res = [['a', 'c'], ['b', 'd']]

My solution is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

arr = np.array([lista, listb]).T
res = arr.tolist()

Is there a simpler way to do it?

>Solution :

[list(a) for a in zip(lista, listb)]

Whether this is simplier might be subjective, but it is one of the options for sure.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading