This is known as flattening, and there are a LOT of implementations out there:
- More on python flatten
- Python tricks
- Flattening lists in Python
How about this, although it will only work for 1 level deep nesting:
>>> x = [["a","b"], ["c"]]
>>> for el in sum(x, []):
... print el
...
a
b
c
From those links, apparently the most complete-fast-elegant-etc implementation is the following:
def flatten(l, ltypes=(list, tuple)):
ltype = type(l)
l = list(l)
i = 0
while i < len(l):
while isinstance(l[i], ltypes):
if not l[i]:
l.pop(i)
i -= 1
break
else:
l[i:i + 1] = l[i]
i += 1
return ltype(l)