How to merge multiple lists into one list in python?

PythonListJoinMerge

Python Problem Overview


> Possible Duplicate:
> Making a flat list out of list of lists in Python
> Join a list of lists together into one list in Python

I have many lists which looks like

['it']
['was']
['annoying']

I want the above to look like

['it', 'was', 'annoying']

How do I achieve that?

Python Solutions


Solution 1 - Python

import itertools
ab = itertools.chain(['it'], ['was'], ['annoying'])
list(ab)

Just another method....

Solution 2 - Python

Just add them:

['it'] + ['was'] + ['annoying']

You should read the Python tutorial to learn basic info like this.

Solution 3 - Python

a = ['it']
b = ['was']
c = ['annoying']

a.extend(b)
a.extend(c)

# a now equals ['it', 'was', 'annoying']

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1452759View Question on Stackoverflow
Solution 1 - PythonRakeshView Answer on Stackoverflow
Solution 2 - PythonBrenBarnView Answer on Stackoverflow
Solution 3 - PythonScottyView Answer on Stackoverflow