Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I merge two lists into a single list?

Tags:

python

I have

a = [1, 2] b = ['a', 'b'] 

I want

c = [1, 'a', 2, 'b'] 
like image 512
sureshvv Avatar asked Aug 12 '10 21:08

sureshvv


People also ask

How do I put multiple lists into one list?

Using + operator The + operator does a straight forward job of joining the lists together. We just apply the operator between the name of the lists and the final result is stored in the bigger list. The sequence of the elements in the lists are preserved.

How do I merge two lists into a list in Python?

In python, we can use the + operator to merge the contents of two lists into a new list. For example, We can use + operator to merge two lists i.e. It returned a new concatenated lists, which contains the contents of both list_1 and list_2.


1 Answers

[j for i in zip(a,b) for j in i] 
like image 59
John La Rooy Avatar answered Oct 09 '22 21:10

John La Rooy