How to flatten a list of tuples into a pythonic list
>>> INPUT = [(1,2),(1,),(1,2,3)]
>>> import itertools
>>> list(itertools.chain.from_iterable(INPUT))
[1, 2, 1, 1, 2, 3]
You could use a list comprehension:
>>> INPUT = [(1,2),(1,),(1,2,3)]
>>> [y for x in INPUT for y in x]
[1, 2, 1, 1, 2, 3]
>>>
itertools.chain.from_iterable
is also used a lot in cases like this:
>>> from itertools import chain
>>> INPUT = [(1,2),(1,),(1,2,3)]
>>> list(chain.from_iterable(INPUT))
[1, 2, 1, 1, 2, 3]
>>>
That's not exactly a one-liner though.