Python merge two lists (arrays)

To merge two (or more) lists (arrays) the operator plus (+) can be used. It will append items of 2nd list to first list and return new list.

newlist = list1 + list2

Example

a1 = ["v1", "v2"]
a2 =  ["v3", "v4"]
newlist = a1 + a2
print newlist
['v1', 'v2', 'v3', 'v4']
Env: Python 2.7.6
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments