165
votes

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?

3
This isn't really a duplicate of that. That question is asking how to flatten a list of nested lists. This question is much more basic and is just asking how to concatenate individual lists. - BrenBarn
@BrenBarn That is exactly what I'm asking. - user1452759

3 Answers

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

Just another method....

164
votes

Just add them:

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

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

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

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

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