0

I got a list of list like:

t0 = [['a', 'b', 'c'], ['d', 'e', 'f'], ['h', 'i', 'j', 'k']]

And I need the output to be:

t1 = ['a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k']

I know I can do that by writing an ugly loop like:

t1 = []
for item in t0:
    t1.extend(item)

Is there any better/elegant way to achieve that?

ciphor
  • 8,018
  • 11
  • 53
  • 70
  • I don't know if this is any more elegant because I am still somewhat of a beginner in Python, but you could do t1+=item instead of t1.extend(item) – CyanogenCX Dec 17 '14 at 01:10
  • @user2780354 - That works as well. However, most Python code I've seen uses `list.extend(item)` to make it clear that we have a list. I mean, `+=` works with *many* types (ints, floats, lists, etc.) where as `list.extend` is only for lists. –  Dec 17 '14 at 01:15

0 Answers0